我在 ASP.NET MVC3 中创建一个网站。我的问题是,当引用的文件似乎位于正确的位置时,我收到“找不到资源”错误。
这是确切的错误消息:
Server Error in '/' Application.
The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /Views/Product/Index.cshtml
问题是,/Views/Product 中有一个 Index.cshtml。
这是我的 Global.asax 的摘录:
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Product", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
解决方案:问题是我通过右键单击并选择“设置为起始页”将 Index.cshtml 设置为“起始页”。根据 nemesv 的建议手动输入 URL 并看到一切正常后,我进入项目设置并将 Web-> 开始操作更改为“当前页面”。