title: Setting an MVC TextBox to Initial Value in Razor
body: <p>I'm new to ASP.NET MVC but I haven't been able to find an explanation for this.</p>
  
  <p>My questions is regarding the difference in the <code>value</code> attribute in the generated HTML when I use <code>@HtmlTextBox()</code> vs. <code>@HtmlTextBoxFor()</code>.</p>
  
  <p>I can set the initial value for an <code>&lt;input&gt;</code> using <code>@Html.TextBox()</code> like this:</p>
  
  <pre><code>@Html.TextBox("Phone", "Initial Value", htmlAttributes: new { id = "txt_phone" })
  </code></pre>
  
  <p>The generated HTML is just what you'd expect:</p>
  
  <pre><code>&lt;input id="txt_phone" name="Phone" type="text" value="Initial Value" /&gt;
  </code></pre>
  
  <p>Please notice the generated <code>value</code> attribute above.</p>
  
  <p>Using <code>@HtmlTextBoxFor()</code> is a different. Please note that I have a very simple model in my view. It has a <code>Phone</code> property which is a <code>String</code>.</p>
  
  <p>Here's an attempt at setting an initial value using <code>@Html.TextBoxFor()</code>:</p>
  
  <pre><code>@Html.TextBoxFor(x =&gt; x.Phone, htmlAttributes: new { id = "txt_phone", value="Initial Value" })
  </code></pre>
  
  <p>The generated HTML, however, does not reflect the <code>value</code> attribute:</p>
  
  <pre><code>&lt;input id="txt_phone" name="Phone" type="text" value="" /&gt;
  </code></pre>
  
  <p><strong>My first question is, "why did the generated HTML not reflect the 'Initial Value' text in my <code>value</code> attribute?"</strong></p>
  
  <p>As many of you know, the "right way" to set the initial value with <code>@HtmlTextBoxFor()</code> is like this:</p>
  
  <pre><code>@Html.TextBoxFor(x =&gt; x.Phone, htmlAttributes: new { id = "txt_phone", Value = "Initial Value" })
  </code></pre>
  
  <p>But look at the generated HTML:</p>
  
  <pre><code>&lt;input Value="Initial Value" id="txt_phone" name="Phone" type="text" value="" /&gt;
  </code></pre>
  
  <p>As you can see it generates a <code>Value</code> attribute (with a capital V) yet it still generates a <code>value</code> attribute with a lowercase v and an empty string!.</p>
  
  <p><strong>My second question then, is, why does <code>@Html.TextBoxFor()</code> require a captial V in <code>Value</code> yet still generate a lower-case v, <code>value</code> with an empty string?</strong></p>
  
  <p>Thanks</p>