I am using asp.net mvc 4 . I want to work with 3 - 4 route pattern , but I can't . it works just with one pattern : this is my RouteConfig file :
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.Add(
new Route("mycontroller/{action}/{mlid}/{countryid}/{cityid}",
new RouteValueDictionary(
new
{ action="myaction",
mlid = UrlParameter.Optional,
countryid = UrlParameter.Optional,
cityid = UrlParameter.Optional,
}),
new HyphenatedRouteHandler())
);
routes.Add(
new Route("{controller}/{action}/{id}",
new RouteValueDictionary(
new { controller = "start", action = "Index",id = UrlParameter.Optional}),
new HyphenatedRouteHandler())
);
I have a controller an action with 8 parameters . I want to use first pattern , but it use second pattern . I used Route Debugger but it does not help me . please help .
EDIT :
I use this code for navigation :
<a href="@Url.Action("myaction", "mycontroller", new { mlid = "1" })">test</a>
but it shows this in address bar :
http://localhost:12911/mycontroller/myaction?mlid=1
I want to show it this :
http://localhost:12911/mycontroller/myaction/1
EDIT :
This is my class :
public class HyphenatedRouteHandler : MvcRouteHandler
{
protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
{
if (requestContext.RouteData.DataTokens["area"] != null)
{
requestContext.RouteData.DataTokens["area"] = requestContext.RouteData.Values["area"].ToString().Replace('-', '_');
}
requestContext.RouteData.Values["controller"] = requestContext.RouteData.Values["controller"].ToString().Replace("-", "_");
requestContext.RouteData.Values["action"] = requestContext.RouteData.Values["action"].ToString().Replace("-", "_");
return base.GetHttpHandler(requestContext);
}
}