views:

35

answers:

1

I am trying to figure out how to route my application to a default controller/task/id when none is specified in a request.

Here is my one routing instruction...

 routes.MapRoute(
    "Default", // Route name
    "{controller}/{action}/{id}", // URL with parameters
    new
    {
     controller = "LML",
     action = "TaskLibrary",
     id = 7
     //id = UrlParameter.Optional
    } // Parameter defaults
   );

Using this, if I enter in 'http://mywebsite/', the proper controller/action/id is called. However, I would like the URL to reflect this. Rather the URL remains untouched from what I entered.

Using routing, is there a way to affect the URL so that it redisplays synced with the controller/action/id it is showing by default? Or do I have to create some sort of redirect action?

+2  A: 

Routing is about mapping a request to an action, not about redirecting.

You could change your default route parameters to default to another action that simply redirects to "LML/TaskLibrary/7"

Phil Brown
Thanks for the quick response. I am just learning MVC. So you are suggesting the default route params hit a controller action that simply redirects to a default URL? Sorry if obvious. Still learning!
John
Keep in mind that default route parameters are used when there's no match on the request. Using your route, the following requests are the same - "/", "/LML", "/LML/TaskLibrary" and "/LML/TaskLibrary/7". It's up to you to decide the best landing page (no parameters so use all defaults) for your site.
Phil Brown