0

I'm beginer in asp.net mvc. I try the routing. but all route formats using by first defined route value. Example all views url finishing with "index" i don't want this url format. and i want localhost:56609/Cuisines/Detail/4/thai but program showing localhost:56609/Cuisines/getCuisineDetail/6/thai . How to do this explain me please.

RouteConfig

routes.MapRoute( _
    name:="RestaurantDetail", _
    url:="{controller}/{action}/{id}/{title}", _
    defaults:=New With {.controller = "Restaurants", .action = "Index", .id =     UrlParameter.Optional, .title = UrlParameter.Optional} _
)

routes.MapRoute( _
    name:="Cuisines", _
    url:="{controller}/Detail/{id}/{title}", _
    defaults:=New With {.controller = "Cuisines", .action = "getCuisineDetail", .id = UrlParameter.Optional, .title = UrlParameter.Optional} _
)

routes.MapRoute( _
    name:="Default", _
    url:="{controller}/{action}", _
    defaults:=New With {.controller = "Home", .action = "Index"} _
)

View

   @<p>@Html.ActionLink(Model(i).Name, "getCuisineDetail", New With {.id = Model(i).CusineID, .title = OnlineSiparis.UrlEditor.CheckUrl(Model(i).Name)}) </p>

enter image description here enter image description here enter image description here

0

1 Answer 1

2

The "RestaurantDetail" route also matches the URL pattern of the more specific "Cuisines" route. Try to change the code so that "Cuisines" is mapped first...

routes.MapRoute( _
    name:="Cuisines", _
    url:="{controller}/Detail/{id}/{title}", _
    defaults:=New With {.controller = "Cuisines", .action = "getCuisineDetail", .id = UrlParameter.Optional, .title = UrlParameter.Optional} _
)

routes.MapRoute( _
    name:="RestaurantDetail", _
    url:="{controller}/{action}/{id}/{title}", _
    defaults:=New With {.controller = "Restaurants", .action = "Index", .id = UrlParameter.Optional, .title = UrlParameter.Optional} _
)
Sign up to request clarification or add additional context in comments.

2 Comments

Yes its works thank you. But i dont understand why cuisines route must first
Because "RestaurantDetail" also matches the pattern specified by "Cuisines" route and the routing provider checks the routes in order, the first one that is mapped will "win". Therefore you have to map the "Cuisines" route first if you want it to match on "{controller}/Detail/{id}/{title}" (@Html.ActionLink(Model(i).Name, "getCuisineDetail" uses the same method to generate the link).

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.