title: Does an action parameter have a default value?
body: <p>How can I find out in a custom ModelBinder in ASP.NET MVC whether I am binding to a parameter that has a default value or not?</p>
  
  <p>Default value:</p>
  
  <pre><code>public void Show(Ship ship = null)
  {
       // ...
  }
  </code></pre>
  
  <p>No default value:</p>
  
  <pre><code>public void Show(Ship ship)
  {
       // ...
  }
  </code></pre>
  
  <p>ModelBinder:</p>
  
  <pre><code>public class ModelBinder : DefaultModelBinder
  {
      public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
      {
          var modelType = bindingContext.ModelType;
  
          // Is it an item from the database?
          if (typeof(IDbObject).IsAssignableFrom(modelType))
          {
              // Get from database...
              var result = BindValue();
  
              if (result == null &amp;&amp; NotOptional()) // Code for NotOptional needed
                  throw new Exception();
  
              return result;
          }
      }
  }
  </code></pre>
  
  <p>I want to know this because I want to show an error message if a user does a request to an action and does not provide all necessary information (which would be all parameters that have no default value).</p>