tags:

views:

24

answers:

1

Hi all,

I want to get the url for my site as "www.ABCD.com/username" without the controller name in MVC architecture, such that when i click the name of the particular user i want to show details of the user with just the name of the user showing in url.

+2  A: 

This should get you going in the right direction:

routes.MapRoute(
    "ViewProfile",                                              
    "{username}",                           
    new { controller = "User", action = "ViewProfile" },
    // new { username = "\w+" } // consider using a username regex here
);

Note that you will need to update the controller and action values to match your application. The ViewProfile action should look something like this:

public ActionResult ViewProfile(string username) { }

Keep in mind that the above route is very greedy and you will have to make sure any other actions which need to be accessed within your application are placed higher up in the route definitions list. Also keep in mind that if a user should pick a username that conflicts with a route you've defined above the ViewProfile route, the user's profile will never be accessible via the rooted path because the other route will override it.

Nathan Taylor
tanq you let me try it out with my logic to pass your routing
kart