public class PostController : YourDefinitionController
{
public ActionResult Test(int id ,int title)
{
return View();
}
}
@Html.ActionLink("Postss", "Test","Post" ,new { title = "asdf",id=3 },null)//in Razor view
// here is route registration
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Post",
"{Post}/{Test}/{title}/{id}",
new { controller = "Post", action = "Test",id=UrlParameter.Optional, title=UrlParameter.Optional }
);
routes.MapRoute(
"Defaultx", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
I expected to see link like /Post/Test/asdf/3 but it is /Post/Test/3?title=3
Why ? How can i fix it?
I would suggest cleaning your code a bit, because there are many things done based on conventions. So keeping code consistent often helps.
Edit: The problem is with wrong route path. You have to change it to
"Post/Test/{title}/{id}"Btw: If you are going to play with routes a bit more, Phil Haack’s blog will be a great resource.