I seem to be having difficult when I try to pass an object from my View to my HttpPOST method.
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.
Here is my HttpPOST method:
[HttpPost]
public async Task<ActionResult> BookClass(MemberClassViewModel memberClassViewModel)
{
return RedirectToAction("Index");
}
The parameter passed in always seems to be NULL.
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.
@model IEnumerable<GymTracker.ViewModel.MemberClassViewModel>
@{
ViewData["Title"] = "BookClass";
}
<h2>Book Class</h2>
@foreach (var item in Model)
{
<form method="post">
<div>
<hr />
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.ClassName)
</dt>
<dd>
@Html.DisplayFor(modelItem => item.ClassName)
</dd>
<dt>
<button>Book Class</button>
<input type="hidden" asp-action="BookClass" asp-controller="Members" value="@item"/>
</dt>
</dl>
</div>
</form>
}
Thanks

<input type="submit" />to submit you form data.