Is there any way to remove some of route values after开发者_JAVA技巧 route was matched but before matched action is executed. My action doesn't contain some of route values and I want to remove them.
In other words, there is some route value which won't be used in my controller (but is used by filters) and I don't want to keep it at action.
I have found an easy solution - define custom RouteHandler:
public class CustomMvcRouteHandler: MvcRouteHandler
{
protected override System.Web.IHttpHandler GetHttpHandler(RequestContext requestContext)
{
requestContext.RouteData.Values.Remove("someValue");
return base.GetHttpHandler(requestContext);
}
}
// ... and when defining the route, set the route handler to be your custom route handler
route.RouteHandler = new CustomMvcRouteHandler();
Anywhere you can get a hold of the RouteData
for the request you can get call:
RouteData.Values.Remove("keyNameOfParameterToRemove");
But this comes with no promise of doing what you want it to do, unless you can expand on why you want to do this so I can test that specific goal.
精彩评论