use*_*115 6 c# asp.net razor asp.net-mvc-3
我刚刚使用Razor引擎创建了一个新的ASP.NET MVC 3项目.我在控制器文件夹中添加了一个控制器,然后在homController.cs我添加了一个视图.
View(index.cshtml)只有这个代码:
@{
ViewBag.Title = "Home";
}
<h2>Home</h2>
Run Code Online (Sandbox Code Playgroud)
当我开始调试时,它显示了这个错误:
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: /
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.225
Run Code Online (Sandbox Code Playgroud)
有什么问题?
你能检查App_Start/RouteConfig.cs,你必须有一个名为homController.cs的控制器的代码:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "hom", action = "Index", id = UrlParameter.Optional }
);
}
Run Code Online (Sandbox Code Playgroud)
我想,你的第一个控制器名称不是'Home',所以你必须更改默认的控制器名称!
| 归档时间: |
|
| 查看次数: |
15138 次 |
| 最近记录: |