我已经搜索了Stack很多年了,阅读了MSDN文档并使用了Bing但是看不出为什么这不会起作用!我已经获得了以下相关代码+路线。名为Browse
的路线运行正常,但productCode
路线的Details
参数始终等于零。如果我制作任何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}
)
答案 0 :(得分:7)
订单在定义路线时很重要。
当您请求site.com/details/abc123
时,我认为它与您的第一条路线相符。
你会得到
controller = "details"
action = "Index"
genre = "abc123"
这就是您的productCode为null的原因。
切换两个route.MapRoute
语句,它应该可以解决您的问题。
您的第二条路线确实将行动设定为info
而不是index
,但我认为这是一个错字?