title: html.hidden for value not set in asp.net MVC core Razor view
body: <p>I am working on an asp.net MVc core application. I have a popup with a form element like this:</p>
  
  <pre><code>@using (Html.BeginForm("AddIVR", "ITPVoice", FormMethod.Post, new { role = "form" }))
   {    
         @*@Html.HiddenFor(m =&gt;m.m_newIVR.Account, new { @value= Model.accountID})*@
         @Html.Hidden("m.m_newIVR.Account", Model.accountID)    
   }
  </code></pre>
  
  <p>I have a viewmodel like this:</p>
  
  <pre><code>public class AccountDetailsViewModel
  {
      public IVRS m_newIVR { get; set; }
  }
  </code></pre>
  
  <p>and IVRS model class like this:</p>
  
  <pre><code> public class IVRS
   {
  
          [JsonProperty("_id")]
          public string Id { get; set; }
  
          [JsonProperty("name")]
          public string Name { get; set; }
  
          [JsonProperty("description")]
          public string Description { get; set; }
  
          [JsonProperty("account")]
          public string Account { get; set; }
  
  }
  </code></pre>
  
  <p>I am trying to populate it in my view like this:</p>
  
  <pre><code>@Html.HiddenFor(m =&gt;m.m_newIVR.Account, new { @value= Model.accountID})
  </code></pre>
  
  <p>but when i see view source, Value is null</p>
  
  <p>I tried using:</p>
  
  <pre><code> @Html.Hidden("m.m_newIVR.Account", Model.accountID)
  </code></pre>
  
  <p>and it shows m_newIVR.Account populated.</p>
  
  <p>Then I am posting the form to controller this action</p>
  
  <pre><code> [HttpPost]       
          public ActionResult AddIVR(AccountDetailsViewModel model)
  {
   return RedirectToAction("AccountDetails", "mycontroller")
  }
  </code></pre>
  
  <p>Although I see that AccountId is populated in view ( using viewsource), but in post action method value of  model.m_newIVR.Account is null.</p>
  
  <p><strong>HTML output looks like this:</strong></p>
  
  <pre><code>        &lt;div id="edit-ivrs-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;"&gt;
  
  
        &lt;div class="modal-dialog"&gt;
  &lt;form action="/ITPVoice/AddIVR" method="post" role="form"&gt;                        &lt;div class="modal-content"&gt;
                              &lt;div class="modal-header"&gt;
  
                                  &lt;h4 class="modal-title"&gt;Add IVR&lt;/h4&gt;
                                  &lt;input id="m_newIVR_Account" name="m_newIVR.Account" type="hidden" value="" /&gt;
                                  &lt;input id="AccountId" name="AccountId" type="hidden" value="56f5e3d77ea022a042665be1" /&gt;
                              &lt;/div&gt;
                              &lt;div class="modal-body"&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>My Questions are:</p>
  
  <ol>
  <li>Why html.hiddenfor is not setting value of the model variable?</li>
  <li>Although html.hidden is setting value, why it is not accessible in post action method ?</li>
  </ol>
  
  <p>Please suggest.</p>