asp.net map route with parameter inside controller and view -


I need to create a url scheme like this

  friends / {userid} / Wishlist  

Where Friend is the controller, wishlist view, and User ID is the ID of the HTA friend, whose wishlist is to see you.

I have set up a route such as

  route. MapPrice ("FriendWishlist", "Friend / {User ID} / wishlist", new {admin = "wishlist", action = "friend list", user id = 123});  

When I try to browse / friend / 123 / wishlist , I get the following error

Public action method '123' was not found on the controller 'GiffrWeb.Areas.Api.Controllers.FriendController'.

Routes are evaluated in MVC, which are declared to them. Your route is declared by default as below as it sounds too much:

  routes. MapRoute ("default", "{controller} / {action} / {id}", new {controller = "home", action = "index", id = urlParameter.optional}); Routes.MapRoute ("FriendWishlist", "Friend / {User ID} / wishlist", new {admin = "wishlist", action = "friend list", userid = 123});  

Then the MVC framework is trying to match the default route before your url buddy / 123 / wishlist . Because it is all variable and everything is a default or optional, this match is guaranteed. It does not check whether the controllers and actions are present and take the related argument. You have a friend moderator category - checked. 123 Action - It goes bang.

Simplest Decision - Declare the default path given above (i.e. swap these two statements) and it should work fine.

I can just add that it looks strange that there is a URL that starts with / friend / Wishlist goes to the controller when you have A friend is a controller (your error message says so). Finally, I can not highly recommend that if you offer custom routing that you check those paths well - as you have seen, the routing engine can not do that which you think Is that so. I recommend either routine goods or Brad Wilson.


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -