title: Set the default value in MVC web application
body: <p>I am trying to set the default Value of a field in an ASP.net MVC web application.</p>
  
  <p>I am using database first so I have added a partial class for meta data as follows:</p>
  
  <pre><code>[MetadataType(typeof(RadioRoutingMetadata))]
  public partial class RadioRouting
  {
  }
  
  public partial class RadioRoutingMetadata
  {
      [DefaultValue("%")]
      public string Slot { get; set; }
  
      [Required(ErrorMessage = "This field is requied")]
      [DefaultValue(0)]
      public int BlockStart { get; set; }
  
      [Required(ErrorMessage = "This field is requied")]
      [DefaultValue(499)]
      public int BlockEnd { get; set; }
  
      [DefaultValue(-1)]
      public int FallBackBaseIdentifier { get; set; }
  }
  </code></pre>
  
  <p>No after reading I see that <code>[DefaultValue(T)]</code> doesn't initialise the field to that value when being created. But do the Html helper methods not look at this field?</p>
  
  <p>here is my view:</p>
  
  <pre><code>&lt;p&gt;
     @Html.LabelFor(model =&gt; model.Slot, htmlAttributes: new { @class = "control-label col-md-2" })
     &lt;span class="field"&gt;
         @Html.EditorFor(model =&gt; model.Slot, new { htmlAttributes = new { @class = "form-control" } })
         @Html.ValidationMessageFor(model =&gt; model.Slot, "", new { @class = "text-danger" })
     &lt;/span&gt;
  &lt;/p&gt;
  
  &lt;p&gt;
      @Html.LabelFor(model =&gt; model.BlockStart, htmlAttributes: new { @class = "control-label col-md-2" })
      &lt;span class="field"&gt;
          @Html.EditorFor(model =&gt; model.BlockStart, new { htmlAttributes = new { @class = "form-control" } })
          @Html.ValidationMessageFor(model =&gt; model.BlockStart, "", new { @class = "text-danger" })
      &lt;/span&gt;
  &lt;/p&gt;
  
  &lt;p&gt;
      @Html.LabelFor(model =&gt; model.BlockEnd, htmlAttributes: new { @class = "control-label col-md-2" })
      &lt;span class="field"&gt;
          @Html.EditorFor(model =&gt; model.BlockEnd, new { htmlAttributes = new { @class = "form-control" } })
          @Html.ValidationMessageFor(model =&gt; model.BlockEnd, "", new { @class = "text-danger" })
      &lt;/span&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>So When I now provide a Create Form I want these default values to be there in the form. </p>
  
  <p>Do I have to initialize the Model object in the controller, set the default values, and then pass it through to the create view as if it was an edit view?</p>
  
  <p>If so how can I create a constructor that initializes all the default values in the partial class?</p>