title: html.TextBoxFor and html.Textbox, POSTing values, model in parameters
body: <p>Alright guys, Need some help!</p>
  
  <p>Im working with asp.net mvc3 razor (and am fairly new to it but did lots of web forms)</p>
  
  <p>Okay so onto the problem</p>
  
  <p>My question revolves around submitting a view.
  I have a very complicated model that my view is based off (strongly typed).</p>
  
  <p>I want to return the model into the arguments in the HttpPost method of the controller. do basically:</p>
  
  <pre><code>public ActionResult Personal()
      {
          DataModel dataModel = new DataModel();
          FormModel model = new FormModel();
          model.candidateModel = dataModel.candidateModel;
          model.lookupModel = new LookupModel();
  
          return View(model);
      }
  
      [HttpPost]
      public ActionResult Personal(FormModel formModel)
      {
          if (ModelState.IsValid)
          {
              //stuff
          }
          return View(formModel);
      }
  </code></pre>
  
  <p>Now...<br>
  I'm having trouble getting values into the formModel parameter on the post method.</p>
  
  <p><strong>This works</strong> (meaning i can see the value)but is tedious as i have to write exactly where it sits in a string every single field:</p>
  
  <pre><code>@Html.TextBox("formModel.candidateModel.tblApplicant.FirstName", Model.candidateModel.tblApplicant.FirstName)
  </code></pre>
  
  <p>It renders like this:</p>
  
  <pre><code>&lt;input name="formModel.candidateModel.tblApplicant.FirstName" id="formModel_candidateModel_tblApplicant_FirstName" type="text" value="Graeme"/&gt;
  </code></pre>
  
  <p><strong>This doesn't work:</strong></p>
  
  <pre><code>@Html.TextBoxFor(c =&gt; c.candidateModel.tblApplicant.FirstName)
  </code></pre>
  
  <p>It renders like this:</p>
  
  <pre><code>&lt;input name="candidateModel.tblApplicant.FirstName" id="candidateModel_tblApplicant_FirstName" type="text" value="Graeme"/&gt;
  </code></pre>
  
  <p>Now I'm assuming the problem lies in the discrepancy of the id's</p>
  
  <p>So please answer me this:</p>
  
  <ol>
  <li>Am i going about this the right way</li>
  <li>Why doesn't textboxfor get the right value/id, and how do i make it get the right value/id so i can retrieve it in a POST(if that is even the problem)?</li>
  <li>Additionally, it seems that textboxfor is restrictive, in the manner that if you have a date time, how do you use the .toshortdate() method? This makes me think textboxfor isn't useful for me.</li>
  </ol>
  
  <hr>
  
  <p>Quick clarification:
  when i say textboxfor isn't working, it IS getting values when i GET the form. So they fill, but on the POST / submission, i can't see them in the formModel in the parameters.</p>
  
  <p>Another side note:<br>
  None of the html helpers work, this is the problem. They aren't appearing in modelstate either.</p>
  
  <hr>
  
  <p><strong>Thanks everyone for the help</strong></p>
  
  <p>Answer:<br>
  <a href="https://stackoverflow.com/questions/8194199/html-textboxfor-and-html-textbox-posting-values-model-in-parameters/8194406#8194406">html.TextBoxFor and html.Textbox, POSTing values, model in parameters</a></p>
  
  <p>It was a problem in my view somewhere, i replaced all the code with the snippet in this answer and it worked. </p>
  
  <p>Thank you again</p>