我是C#MVC项目类型的新手,当我创建一个空的C#MVC项目时,我注意到以下错误:
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/ControllerName/Index.aspx
~/Views/ControllerName/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/ControllerName/Index.cshtml
~/Views/ControllerName/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
Run Code Online (Sandbox Code Playgroud)
我在Views文件夹下有"Index.cshtml"文件.为什么MVC引擎不直接在Views文件夹下?我该如何解决这个问题?
我的RouteConfig.cs内容是:
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = <ControllerName>, action = "Index", id = UrlParameter.Optional }
);
Run Code Online (Sandbox Code Playgroud)
我的控制器内容:
public ActionResult Index()
{
return View();
}
Run Code Online (Sandbox Code Playgroud)