title: ASP.NET MVC 4 RC Web API ModelState error for optional url parameters which are nullable
body: <p>I wanted to create a global valdiation attribute for my Web API. So I followed the <a href="http://www.asp.net/web-api/overview/web-api-routing-and-actions/video-custom-validation" rel="noreferrer">tutorial</a> and ended up with the following attribute:</p>
  
  <pre><code>public class ValidationActionFilter : ActionFilterAttribute
  {
      public override void OnActionExecuting(HttpActionContext actionContext)
      {
          if (actionContext.ModelState.IsValid)
          {
              return;
          }
  
          var errors = new List&lt;KeyValuePair&lt;string, string&gt;&gt;();
          foreach (var key in actionContext.ModelState.Keys.Where(key =&gt;
              actionContext.ModelState[key].Errors.Any()))
          {
              errors.AddRange(actionContext.ModelState[key].Errors
                    .Select(er =&gt; new KeyValuePair&lt;string, string&gt;(key, er.ErrorMessage)));
          }
  
          actionContext.Response =
              actionContext.Request.CreateResponse(HttpStatusCode.BadRequest, errors);
      }
  }
  </code></pre>
  
  <p>Then I added it to global fitlers in the Global.asax:</p>
  
  <p><code>configuration.Filters.Add(new ValidationActionFilter());</code></p>
  
  <p>It works great with most of my actions but not as expected with actions that have optional and nullable request parameters.</p>
  
  <p>For example:</p>
  
  <p>I created a route:</p>
  
  <pre><code>routes.MapHttpRoute(
      name: "Optional parameters route", 
      routeTemplate: "api/{controller}", 
      defaults: new { skip = UrlParameter.Optional, take = UrlParameter.Optional });
  </code></pre>
  
  <p>And an action in my <code>ProductsController</code>:</p>
  
  <pre><code>public HttpResponseMessage GetAllProducts(int? skip, int? take)
  {
      var products = this._productService.GetProducts(skip, take, MaxTake);
  
      return this.Request.CreateResponse(HttpStatusCode.OK, this._backwardMapper.Map(products));
  }
  </code></pre>
  
  <p>Now when I request this url: <code>http://locahost/api/products</code> I get the a response with 403 status code and the following content:</p>
  
  <pre><code>[
  {
      "Key": "skip.Nullable`1",
      "Value": "A value is required but was not present in the request."
  },
  {
      "Key": "take.Nullable`1",
      "Value": "A value is required but was not present in the request."
  }
  ]
  </code></pre>
  
  <p>I believe this should not appear as a validation error since these parameters are both optional and nullable.</p>
  
  <p>Have anyone encountered this problem and found a solution?</p>