7

I've searched Stack for ages, read the MSDN docs and used Bing but cannot see why this won't work! I've got the relevant code below + the routes. The route called Browse works just fine, but the productCode param for the Details route is always equal to nothing. If I make any mods I keep getting the 'resource not found' 404 page.

' 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

The routes are:

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}
    )

1 Answer 1

7

The order does matter when defining your routes.

When you request site.com/details/abc123 I think it matches your first route.

You will get

controller = "details"

action = "Index"

genre = "abc123"

Which is why your productCode is null.

Switch the two route.MapRoute statements around, it should fix your problem.

Your second route does have action set to info rather than index, but i'm assuming that is a typo?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.