asp.net-mvc – ASP.NET MVC4路由问题

我已经搜索了Stack多年,阅读了MSDN文档并使用了Bing,但是看不出为什么这不起作用!我在路线下面有相关的代码.名为Browse的路由工作得很好,但Details路由的productCode参数总是等于零.如果我制作任何mods,我会继续获得“找不到资源”404页面.

' Lives in controller called 'Details'
' Usage: site.com/details/abc123
Function Index(productCode As String) As ActionResult

' Lives in controller called 'Browse'    
' Usage: site.com/browse/scifi/2
Function Index(genre As String, Optional page As Integer = 1) As ActionResult

路线是:

routes.MapRoute( _
        "Browse", _
        "{controller}/{genre}/{page}", _
        New With {.controller = "Browse", .action = "Index", .id = UrlParameter.Optional, .page = UrlParameter.Optional}
    )

    routes.MapRoute( _
        "Details", _
        "details/{productCode}", _
        New With {.controller = "Details", .action = "Info", .productCode = UrlParameter.Optional}
    )
订单在定义路线时很重要.

当您请求site.com/details/abc123时,我认为它与您的第一条路线相符.

你会得到

controller =“details”

action =“索引”

genre =“abc123”

这就是您的productCode为空的原因.

切换两个route.MapRoute语句,它应该解决你的问题.

你的第二条路线确实将动作设置为信息而不是索引,但我假设这是一个错字?

相关文章
相关标签/搜索