c# - ASP.NET MVC 路由返回 null

标签 c# asp.net-mvc routes

我正在尝试获取以下路由的 URL:

RouteTable.Routes.MapRoute(
    null,
    "cinema",
    new
{
    Controller = "CinemaListings",
    Action = "ShowCinemaLandingPage",
    SiteArea = "CinemaTimes",
    MainLandingPage = true
});

我尝试了以下方法来生成 URL:

<%:Url.Action("ShowCinemaLandingPage", "CinemaTimes", new { SiteArea = "CinemaTimes", MainLandingPage = true})%>
<%:Url.RouteUrl(new { Controller = "CinemaTimes", Action = "ShowCinemaLandingPage", SiteArea = "CinemaTimes", MainLandingPage = true })%>    

我也尝试过只使用 Controller 和 Action 名称。我返回 null - 我错过了什么?

最佳答案

这行不通吗?

<%:Url.Action("ShowCinemaLandingPage", "CinemaListings", new { SiteArea = "CinemaTimes", MainLandingPage = true })%>

从您的代码看来,您混淆了 SiteAreaController 值。因此,您没有在 Url.Action 中提供 Controller 名称,而是提供了两次 SiteArea(作为第二个参数和附加路由值)。

关于c# - ASP.NET MVC 路由返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6692477/

相关文章:

c# - 自定义过滤器属性注入(inject)依赖

php - 如何更改登录路径名称

c# - 检测什么进程/程序启动我的进程/程序

c# - Scalebreakstyle 在图表中不起作用

c# - 如何使用 Linq 从 List<Rectangle[]> 中选择矩形

c# - 添加性能计数器类别挂起计算机

c# - 在 AccountController 之外配置 UserManager 和 UserStore?

c# - 如何修复 InvalidOperationException : The model item passed into the ViewDataDictionary is of type

ruby-on-rails - 将 ID 传递到静态路由 - 匹配 page.url => "pages#show"、 :id => page. id - 不起作用

node.js - 路线和景观