View:
@model MyApp.Models.Activity
@using (Html.BeginForm("Activity_Details", "Activity", FormMethod.Post))
{
@Html.ValidationSummary(true)
@Html.AntiForgeryToken()
@Html.HiddenFor(model => model.ActivityName)
@Html.HiddenFor(model => model.ActDate)
@Html.HiddenFor(model => model.DateAccomplished)
@Html.HiddenFor(model => model.Participants)
<div class="body-header">
<div>
<h2>Activity Information</h2>
</div>
<br />
<div class="buttons">
<input type="submit" name="submitButton" value="Save" class="button save icon" />
<a class="button" href="@Url.Action("Activity_List", "Activity")"><span class="back icon"></span>Back</a>
</div>
</div>
<br />
<div class="content-wrapper">
<div class="sub-content">
<div class="item">
<span>@Html.DisplayNameFor(model => model.ActivityName)</span>
@Html.DisplayFor(model => model.ActivityName)
</div>
<div class="item">
<span>@Html.DisplayNameFor(model => model.ActDate)</span>
@Html.DisplayFor(model => model.ActDate)
</div>
<div class="item">
<span>@Html.DisplayNameFor(model => model.DateAccomplished)</span>
@Html.DisplayFor(model => model.DateAccomplished)
</div>
</div>
<div class="sub-content">
<table cellspacing="0">
<thead>
<tr>
<th>Last Name</th>
<th>First Name</th>
<th>Actual Amount</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model.Participants)
{
<tr>
<td>@item.LastName</td>
<td>@item.FirstName</td>
<td>@item.Amount</td>
</tr>
}
</tbody>
</table>
</div>
</div>
}
Controller:
[HttpPost()]
public ActionResult Activity_Details(string submitButton, Activity model)
{
//AFTER CLICKING THE SUBMIT BUTTON
//model.Participants doesnt retained its values
return View(model);
}
public class Activity
{
public string ActivityName { get; set; }
public DateTime ActDate { get; set; }
public DateTime DateAccomplished { get; set; }
public virtual IEnumerable<Participant> Participants { get; set; }
}
public class Participant
{
public string LastName { get; set; }
public string FirstName { get; set; }
public string Amount { get; set; }
}
I have these Models Activity and Participant which will be displayed in one view and the Participant Model will iterate to create a table.
My Problem now is I need to Update the "Amount" per participants after clicking the submit button and whats happening right now is that when the Model is passed back to ActionResult...Participants model is null and only the Activity Model has data.