我正在开发一个ASP.NET MVC3应用程序。
在视图中,我创建了一个名为Home的文件夹和一个名为Index的视图。
然后我创建了一个Controller HomeController。
在控制器中我添加了:
public ActionResult Index()
{
return View();
}
但是当我运行应用程序时,我收到了这个错误:
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: /
如果我添加到地址栏:/ Home / Index视图正常加载。
如何在加载时自动将应用程序转到Home / Index?
感谢您的帮助
答案 0 :(得分:1)
您需要添加指向路径的Global.asax文件的路径。
routes.MapRoute("Default", "{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);