Asp.net mvc 4 即使路由匹配,Mvc路由也不起作用

Asp.net mvc 4 即使路由匹配,Mvc路由也不起作用,asp.net-mvc-4,view,controller,routing,action,Asp.net Mvc 4,View,Controller,Routing,Action,我正在尝试创建一条新路线。。。代码如下: routes.MapRoute( name: "Services", url: "Administration/{controller}/{action}/{id}", defaults: new { controller = "Services", action = "Index", id = UrlParameter.Optional }); routes.MapRoute( name: "Default",

我正在尝试创建一条新路线。。。代码如下:

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 });
现在,当我单击actionlik时,它会将我重定向到正确的控制器上:

@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
它不在管理文件夹内查看!! 相反,它以这种方式工作:

return View("~/Views/Administration/Services/Index.cshtml");
哪里错了


谢谢

看起来您不太了解路由,或者路由与视图分辨率不是一回事。更改URL以访问操作方法不会使其在新文件夹中搜索视图。因此,您需要执行以下操作之一:

  • 将视图保留在错误消息建议的某个文件夹中
  • 手动指定视图:
    返回视图(“~/Views/Administration/Services/Index.cshtml”)
  • 了解如何使用MVC区域
  • 手动将其他文件夹添加到视图引擎使用的列表中
  • 实现您自己的视图引擎

  • 我个人推荐选项1。

    谢谢。。我已经采纳了你的第一个建议。。没有。。老实说,现在我想我还不明白路线:(