Using a Parameter Attribute to set a Default Value in MVC
A couple days ago I came across a breaking change in ASP.NET MVC PR4 that wasn’t reported. The breaking change is that defaults from routes are no longer used as defaults for parameters in the action method, if no appropriate parameter is found in the request. Basically what this means is the following: I have the following route: URL: /home Controller: Home Action: Index Defaults = page: 1 I set the page so that it always defaults to “1” if no value is found in the query string for “page”. So when a request is executed, the Route passes back the RouteData.Values = controller: “Home”, action: “Index”, page: 1. Then it goes through it’s normally processing and the value of the page’s query string is passed in to my action method for the page parameter. So if query string page = 1 then 1, query string page = 2 then 2, and so on. This is how it worked in PR3 and how I understood it was suppose to work as a concept. However, in PR4, this doesn’t work anymore because of Line 166 in ControllerActionInvoker. It specifically checks that the value is in the route values. However they are always going to be in the route values if they have been defined as a default. ...