如何默认您的 asp.net-mvc 站点首先查找 razor 视图?

发布于 2024-12-18 11:45:03 字数 255 浏览 4 评论 0原文

我正在将所有视图转换为 razor,因此我创建了所有新视图文件,但没有删除 aspx 文件(我只是将它们从项目中排除)。当我去测试我的网站时,它似乎尝试查找并加载 aspx 文件。当我删除这些文件时,它工作正常并且默认为我的 razor cshtml 文件。

我的问题是,我想保留我的 aspx 文件一段时间(至少直到我知道一切正常)。

是否有一个 asp.net-mvc 站点首先查找 razor 视图文件,这样我就不需要删除我的 aspx 文件来使其正常工作?

I am converting all of my views over to razor so I have created all new view files but I haven't deleted the aspx file (I just have them excluded from the project). When i go to test my site, it seems to try to look for and load the aspx files. When I delete these files, it works fine and defaults to my razor cshtml files.

My issues, I that i want to keep my aspx files around for a little bit (at least until i know everything is working).

Is there anyway to have an asp.net-mvc site look for razor view files first so i don't need to delete my aspx files to get this to work?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

皓月长歌 2024-12-25 11:45:03

视图引擎的默认顺序是 Web Forms,然后是 Razor。只需更改顺序即可。

protected void Application_Start() {
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine());
ViewEngines.Engines.Add(new WebFormViewEngine());
// 此处剩余的调用
// ...
}

The default order for view engines is Web Forms then Razor. Just change the order.

protected void Application_Start() {
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new RazorViewEngine());
ViewEngines.Engines.Add(new WebFormViewEngine());
// remaaining calls here
// ...
}

莳間冲淡了誓言ζ 2024-12-25 11:45:03

在将网站从 webforms 迁移到 mvc 时,我遇到了同样的问题。然而我遇到了 MVC 贪婪的问题。我的网站默认使用 mvc 视图,而不是 Web 表单。最终我所做的是在网络表单的根目录下创建一个新文件夹并将其设置为新的应用程序起点。然后将 mvc 站点上传到此文件夹中。一旦我知道一切顺利,我就可以删除网络表格。我发现这是最好的选择。

编辑:应该提到我尝试了忽略路由来忽略.aspx页面 - 对我来说根本不起作用。

I ran into the same issue when migrating a site from webforms to mvc. However I encountered the issue that MVC is greedy. My site would default to the mvc views and not the webforms. Ultimately what i did was create a new folder off the root of the webforms and set it as new application starting point. Then upload the mvc site into this folder. Then once i know all is well then i can take the webforms down. I found this to be best option.

Edit: Should've mentioned i tried the ignore routes thing to ignore .aspx pages - did not work for me at all.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文