title: Form Binding with MVC and Reading Values from Model
body: <p>I have implemented a simple form in MVC with Razor syntax. </p>
  
  <pre><code>@model QuisenberryMVC001.Models.ConsoleCommand    
  
  @using (Html.BeginForm())
  {
      &lt;fieldset&gt;
          &lt;legend&gt;Product&lt;/legend&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.input)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.TextBoxFor(model =&gt; model.input)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.output)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.TextAreaFor(model =&gt; model.output)
          &lt;/div&gt;
  
          &lt;input type="submit" value="Run" /&gt;
      &lt;/fieldset&gt;
  }
  </code></pre>
  
  <p>The model:</p>
  
  <pre><code>public class ConsoleCommand
      {
          public String input {get; set;}
          public String output { get; set;}
      }
  </code></pre>
  
  <p>This form displays a text box to accept input and a text area to display output. I have implemented a controller to prepare the output. Ultimately, this will be done by the model.</p>
  
  <p>Here is the controller:</p>
  
  <pre><code>[HttpPost]
  public ActionResult MyConsole(ConsoleCommand command)
  {
      ViewBag.Message = "My Console";
      command.output += "My Output";
      return View(command);
  }
  </code></pre>
  
  <p>I would like for clicking the "Run" button to update the text area with the text "My Output". Instead, it displays whatever value the user typed.</p>
  
  <p>When I debug the application, I see that <code>command.output</code> actually is "My Output" when <code>return View(command)</code> is reached. I am unable to see what value the view receives, as putting a watch on <code>model</code> or <code>model.output</code> results in an error like <code>The name 'model' does not exist in the current context</code>.</p>
  
  <p>It looks the values are ready correctly from the form but not written correctly to the form. How do I fix binding?</p>