MvcSiteMapProvider includes extra route values
-
08-01-2021 - |
Question
I have an action method that can take an optional id parameter.
public ActionResult Details(int id = 0) {...}
and a site node that should link to the action method with empty id.
<mvcSiteMapNode title="This Object" controller="MyController" action="Details" />
Unfortunately, things don't work out as expected. Most of the time the generated link is /MyController/Details as desired, but if I am currently in "/MyContoller/Details/99", the generated link is /MyContoller/Details*/99*.
Question: How can I get mvcSiteMapNode to ignore the id param when generating a link?
Thanks, Duffy
Solution
I didn't realize I could just add random extra parameters to the mvcsitemapnode. (Mvcsitemap is great but the documentation could do more than just repeat the names of each function...) I ended up just passing in a parameter that effectively overwrote the "99" with a neutral value. Probably not the prettiest approach but solved the problem.