I have an action in controller:
public ActionResult Close(DocType docType)
{
return View();
}
where DocType is a simple enum. I want to have 2 different links to the same action but with different parameters. I have tried this:
<mvcSiteMapNode title="Accounting" clickable="false" imageUrl="~/Content/Images/Buttons/MenuButtons/billing.png" visibility="path">
<mvcSiteMapNode title="Payments" controller="Payment" action="Index"></mvcSiteMapNode>
<mvcSiteMapNode title="Closing WO" controller="Payment" action="Close" docType="2"></mvcSiteMapNode>
<mvcSiteMapNode title="Closing WS" controller="Payment" action="Close" docType="4"></mvcSiteMapNode>
</mvcSiteMapNode>
But in the menu I have 2 links without any parameters: "/Payments/Close"
What's wrong? How to add parameters into mvcSiteMapNode?
Here are my RouteConfig:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
If you want to use your default route, you have to use
idfor the route key (since it only supports the keyscontroller,actionandid). If you don't, you will get a route with a query string?docType=2, since this is extra undefined information that is not part of the route.Otherwise, you need to have a route with the key
{docType}. Either way, the key names must match in order to generate URLs correctly (as they need to in MVC when usingActionLink).