Tôi đã tìm kiếm Stack theo độ tuổi, đọc tài liệu MSDN và sử dụng Bing nhưng không thể thấy tại sao điều này không hoạt động! Tôi đã có mã có liên quan bên dưới + các tuyến đường. Tuyến đường được gọi là Browse
hoạt động tốt, nhưng thông số productCode
cho tuyến đường Details
luôn bằng với không có gì. Nếu tôi thực hiện bất kỳ mod nào, tôi tiếp tục nhận được trang 404 'không tìm thấy tài nguyên'.Vấn đề định tuyến ASP.NET MVC4
' 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
Các tuyến đường bao gồm:
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}
)