ASP.NET route passing string value -


I am trying to keep a page on an asp.net mvc based web site where users instead of a page's permission Name is allowed to choose from id. I would have thought that the route should be something like this:

  routes. MapRoute ("Customer View", "Customer / Details / {User Name}", New {username = ""}); Routes.MapRoute ("default", "{controller} / {action} / {id}", new {controller = "home", action = "index", id = "0"});  

But whenever I use HTML I like a normal route:

  routes MapRoute ("customer view", "customer / description / {username}", new {controller = "customer", action = "description", user name} = ""}});  

But I feel that more problems arise when it makes a mistake, which should be implemented by two.

I'm not sure that I'm completely understanding the question ... are you saying That you want:

  1. A route {controller} / {action} / {username} handles the URL where the third token is a string, Mailing Actions where string is the "username" argument, and

  2. another route {controller} / {action} / {id} handles that URL where the third Token is an integer, mailing function where Is an integer "id" argument?

If yes, check it out which one takes, it should let you do something like this:

  Routes. New {username = ""} new {username = "" [^ 0] "MapRoute" ("customer view", "{controller} / {action} / {username}", new {controller = "customer", action = "description" - 9] + "});  

This should be the reason for matching the user name in any way with an untested obstruction, where the third token contains at least one non-digit character.

Of course, if the user names are required to get a complete score then it can not work for you. In that case, you may need to create a special route for each action that accepts the user name instead of the id.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -