My question is very similar other questions. When using an ActionLink in MVC .Net 4.5, I am getting a query string for one parameter, instead of just a URL path. I tried the solution HERE, but it did not work.
CODE-
Inside RouteConfig.cs -
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "MyControllerRoute",
url: "{controller}/{action}/{id}/{description}",
defaults: new { controller = "MyController", action = "MyAction", id = UrlParameter.Optional, description = UrlParameter.Optional }
);
Inside HomeController.cs -
public ActionResult Index(){
--do stuff--
return View();
}
Inside MyController.cs -
public ActionResult Vote(int id, string description){
--do stuff--
return View();
}
Inside Index.cshtml
@Html.ActionLink(
"This is stuff",
"MyAction",
"MyController",
new { id = 123, description = "This-is-stuff" },
null)
GETTING THIS RESULT - (NOT WHAT I WANT)
<a href="/MyController/MyAction/123?description=This-is-stuff">This is stuff</a>
DESIRED RESULT - (HOW CAN I GET THIS?)
<a href="/MyController/MyAction/123/This-is-stuff">This is stuff</a>
MyControllerRoutebefore the default route. And removeid = UrlParameter.Optional, description = UrlParameter.Optionalfrom theMyControllerRouteroute (only the last parameter can be marked as optionalMyControllerRouteroute as optional. Is there ever a case where you would only provide eitheridordescription? (in which case you would need another solution)