Hi guys,
I am struggling with generating outbound urls in asp.net mvc 2. Here is the scenario.
Controller: MoveController Action: Index() View: Index.aspx
Now what I would like is to have multiple urls mapping to same controller (MoveController) and action (Index) with different parameter (locationId) value
e.g.
- url -> RouteData
- /Production/ -> Move/Index/1
- /Installation/ -> Move/Index/2
- /Move/3/ -> Move/Index/3
My mapping look like this:
public static void RegisterRoutesTo(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{*favicon}", new
{
favicon = @"(.*/)?favicon.ico(/.*)?"
});
routes.MapRoute(
null, // Route name
"Production/{locationId}", // URL with parameters
new
{
controller = "Move",
action = "Index"
}, // Parameter defaults
new
{
locationId = @"\d+"
}// constraint for Production url
);
routes.MapRoute(
null, // Route name
"Installation/{locationId}", // URL with parameters
new
{
controller = "Move",
action = "Index"
}, // Parameter defaults
new
{
locationId = @"\d+"
}// constraint for Production url
);
routes.MapRoute(
null, // Route name
"Move/{locationId}", // URL with parameters
new
{
controller = "Move",
action = "Index"
}, // Parameter defaults
new
{
locationId = @"\d+"
}// constraint for Production url
);
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new
{
controller = "Home",
action = "Index",
id = UrlParameter.Optional
} // Parameter defaults
);
}
Now to generate the outbound urls in my master page menu, I am doing something lik ethis
<%= Html.ActionLink("Production", "Index", "Move", new{locationId = 1}, null)%>
<%= Html.ActionLink("Installation", "Index", "Move", new{locationId = 2}, null)%>
But the above generates
- /Production/1
- /Production/2
which is correct, but how can i tell it to generate
- /Production/ when the locationId =1
- /Installation/ when locationId = 2
Any Idea?
Awaiting,