asp.net-mvc-5 - Url.Action 可以在 MVC5 中指定路由吗?

标签 asp.net-mvc-5

在我们的默认布局中,我们将 Logo 包裹在 URL 中。操作可导航回主屏幕。但是,如果我们位于某个区域,它会尝试导航到该区域中不存在的家庭 Controller 。

我们的家庭 Controller 是Submission。这是布局文件中的链接:

<a class="navbar-brand custm-navbar-brand" href="@Url.Action("Index", "Submission")">
    <img src="@Url.Content("~/Content/images/eed-main-logo.png")" alt="E-Editorial Discovery" width="335" height="56">
</a>

如果我在这样的区域:/Admin/Security/Index
上面的链接尝试转到:/Admin/Submission/Index
但它应该转到:/Submission/Index

我确信有更好的方法,但我还没有找到。

最佳答案

像参数一样指定区域。所以你的第一行应该是:

<a class="navbar-brand custm-navbar-brand" href="@Url.Action("Index", "Submission", new { Area = "AreaName" })">

关于asp.net-mvc-5 - Url.Action 可以在 MVC5 中指定路由吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32379021/

相关文章:

c# - 带条件的 asp.net mvc 5 SelectListItem

javascript - MVC - 无法加载资源 : the server responded with a status of 500 (Internal Server Error)

c# - ASP MVC 5 在 URL 中隐藏区域(路由)

asp.net-mvc - Visual Studio 2013-未安装Visual Basic/Visual C#Web模板

asp.net - 将SQLite与ASP.Net MVC5一起使用的连接字符串

javascript - MVC .net中热敏打印机无打印对话框直接打印

asp.net-mvc - 如何防止 EnumDropDownListFor 将 0 设置为 optionLabel 值?

c# - 从C#将音频流传输到网页

iframe - Azure AD Owin 与 Iframe 解决方案

c# - DataContext db = new DataContext() - 作为全局