我正在尝试创建一条新路线......这里是代码:
routes.MapRoute(
name: "Services",
url: "Administration/{controller}/{action}/{id}",
defaults: new { controller = "Services", action = "Index", id = UrlParameter.Optional });
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional });
现在,当我点击动作时,它会将我重定向到正确的控制器上:
@Html.ActionLink("Services", "Index","Services")
这里是服务控制器中的索引操作
public ActionResult Index()
{
return View(); //Here it is where I stop debug
}
我到达了行动..现在我的自定义路线应该重定向到我的视图。正确? 我让你看到我停止调试后看到的内容:
如何看待一切看起来很有价值。但是当我得到以下错误时:
The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Services/Index.aspx
~/Views/Services/Index.ascx
~/Views/Shared/Index.aspx
~/Views/Shared/Index.ascx
~/Views/Services/Index.cshtml
~/Views/Services/Index.vbhtml
~/Views/Shared/Index.cshtml
~/Views/Shared/Index.vbhtml
它看起来不在Administration文件夹中的视图!! 这样就可以了:
return View("~/Views/Administration/Services/Index.cshtml");
哪里错了?
谢谢
答案 0 :(得分:1)
看起来你不太了解路由,或者路由与视图分辨率不同。更改URL以访问操作方法不会使其搜索视图的新文件夹。因此,您需要执行以下操作之一:
return View("~/Views/Administration/Services/Index.cshtml");
我个人推荐选项1。