Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Razor Actionlink选择控制器的规则是什么?它没有使用正确的命名空间_Razor_Controller_Asp.net Mvc 5_Html.actionlink - Fatal编程技术网

Razor Actionlink选择控制器的规则是什么?它没有使用正确的命名空间

Razor Actionlink选择控制器的规则是什么?它没有使用正确的命名空间,razor,controller,asp.net-mvc-5,html.actionlink,Razor,Controller,Asp.net Mvc 5,Html.actionlink,Html.ActionLink未生成正确的链接。根据我对名称空间应该如何工作的理解,它没有选择正确的名称空间 我有这两个控制器,每个控制器在不同的名称空间中 namespace pub.Areas.dashboard.Controllers.Generated.FilterPartialWrapper { public class FilterPartialWrapperController : Controller { public ActionResult Inde

Html.ActionLink未生成正确的链接。根据我对名称空间应该如何工作的理解,它没有选择正确的名称空间

我有这两个控制器,每个控制器在不同的名称空间中

namespace pub.Areas.dashboard.Controllers.Generated.FilterPartialWrapper {

    public class FilterPartialWrapperController : Controller {
        public ActionResult Index() {
            return View("~/Areas/dashboard/Views/Generated/FilterPartialWrapper/FilterPartialWrapper.cshtml");
        }
   }
}

namespace pub.Areas.dashboard.Controllers.Generated.PickerPartialWrapper {

    public class PickerPartialWrapperController : Controller {
        public ActionResult Index() {
            return View("~/Areas/dashboard/Views/Generated/PickerPartialWrapper/PickerPartialWrapper.cshtml");
        }
    }
}
PickerPartialWrapper.cshtml中生成的所有内容都是正确的

现在,在FilterPartialWrapper.cshtml中,我想生成一个指向.cshtml的链接,该.cshtml在“FilterPartialWrapper”名称空间中有一个控制器。但是,它不起作用,它不是从定义控制器继承名称空间,而是选择另一个名称空间

<!-- This is what should be generated -->
<a href="/dashboard/generated/filterpartialwrapper/authsitecredential">View </a>

<!-- Both of these generate /dashboard/Generated/PickerPartialWrapper/AuthURLCredential -->

<p>@Html.ActionLink("View", "index", "AuthURLCredential")</p>
<p>@Html.ActionLink("View", "index","AuthSiteCredential",new {arg=1},null)</p>
我使用的是MVC5。有什么想法吗

谢谢


john

你的路由是什么样子的?我添加了路由,虽然这不重要,因为页面本身显示正确。我建议你使用属性路由。在我看来,它更干净,你也不必担心名称空间。谢谢你,Nathan,我实际上在MVC4中启动了我的项目,并在MVC5B/c中重新启动了它,尽管我打算先做一些基础设施工作。既然我知道我会这样做,我会先解决这个问题,看看这是否能解决ActionLink的问题。至于为什么它不起作用,这不是一个解决问题的方法,但使用属性路由解决了这个问题。谢谢你,内森!
context.MapRoute(name: "Picker Partial Scaffolds",
   url: "dashboard/Generated/PickerPartialWrapper/{controller}/{action}/{id}",
   defaults: new { action = "Index", id = UrlParameter.Optional },
   namespaces: new string[] { "pub.Areas.dashboard.Controllers.Generated.PickerPartialWrapper" });

context.MapRoute(name: "Filter Partial Scaffolds",
   url: "dashboard/Generated/FilterPartialWrapper/{controller}/{action}/{id}",
   defaults: new { action = "Index", id = UrlParameter.Optional },
   namespaces: new string[] { "pub.Areas.dashboard.Controllers.Generated.FilterPartialWrapper" }); 

context.MapRoute(name: "Dashboard",
   url: "dashboard/{controller}/{action}/{id}",
   defaults: new { action = "Index", id = UrlParameter.Optional },
   namespaces: new string[] { "pub.Areas.dashboard.Controllers" });