title: C# MVC - Passing ViewModel object from View to Controller
body: <p>I seem to be having difficult when I try to pass an object from my View to my HttpPOST method.</p>
  
  <p>Upon clicking the button in my View, the code hits the POST method but no data is being passed through. I have tried updating the method parameters and passing different values (like Ints) but to no avail.</p>
  
  <p>Here is my HttpPOST method:</p>
  
  <pre><code>    [HttpPost]
      public async Task&lt;ActionResult&gt; BookClass(MemberClassViewModel memberClassViewModel)
      {
          return RedirectToAction("Index");
      }
  </code></pre>
  
  <p>The parameter passed in always seems to be NULL.</p>
  
  <p>Here is the code for my View. The Model is of type IEnumerable   i.e a list of my ViewModel objects, which in my case is 3 objects. What I am trying to achieve is, clicking on the appropriate button, will result in that one object being passed back to my HttpPOST method. I've tried passing in various values in the 'value' parameter.</p>
  
  <pre><code>@model IEnumerable&lt;GymTracker.ViewModel.MemberClassViewModel&gt;
  
  
  @{
      ViewData["Title"] = "BookClass";
  }
  
  &lt;h2&gt;Book Class&lt;/h2&gt;
  
  @foreach (var item in Model)
  {
      &lt;form  method="post"&gt;    
          &lt;div&gt;    
              &lt;hr /&gt;
              &lt;dl class="dl-horizontal"&gt;    
                  &lt;dt&gt;
                      @Html.DisplayNameFor(model =&gt; model.ClassName)    
                  &lt;/dt&gt;
                  &lt;dd&gt;
                      @Html.DisplayFor(modelItem =&gt; item.ClassName)
                  &lt;/dd&gt;
                  &lt;dt&gt;    
                      &lt;button&gt;Book Class&lt;/button&gt;
                      &lt;input type="hidden" asp-action="BookClass" asp-controller="Members" value="@item"/&gt;    
                  &lt;/dt&gt;        
              &lt;/dl&gt;
          &lt;/div&gt;    
      &lt;/form&gt;    
  }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/JoEim.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/JoEim.jpg" alt="enter image description here"></a>
  Any help will be appreciated,</p>
  
  <p>Thanks</p>