I have the following route defined in global.asax
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Portal", action = "Index", id = UrlParameter.Optional }
);
I can't control whether users access the page with "/useraccount/edit/1" or "/useraccount/edit?id=1". When using the UrlHelper Action method to generate a url, the id value is not contained in RouteData if id is passed as a querystring parameter.
new UrlHelper(helper.ViewContext.RequestContext).Action(
action, helper.ViewContext.RouteData.Values)
I'm looking for a consistent way to access the id value, regardless of which url was used to access the page, or a way to customize the initialization of the RouteData object so that it checks the QueryString for missing route parameters and adds them if they are found.
Extending Route ended up being the easiest solution for my needs; Thank you for the suggestions! Let me know if there are any glaring issues (other than the class name) with my solution.
FrameworkRoute.cs
Global.asax.cs