So I have a form that displays addresses for people (most of these people have multiple addresses) the form displays the current address listed and will allow them to update the city name. When I click the save button, the model does not get passed back. Some of this had to be modified so the logic could be simplified so sorry ahead of time if it seems off. When I save the HttpPost actionresult method returns the model as null. What am I doing wrong?
Controller:
[HttpGet]
public ActionResult CANBudgets(int addressId)
{
PersonRepository.PersonDetailsModel model = new PersonRepository.PersonDetailsModel();
model.Addresses= model.Addresses.Where(a => a.Address_Id == addressId).ToList();
return PartialView(model);
}
[HttpPost]
public ActionResult Address(PersonModel.PersonDetailsModel pplModel)
{
return PartialView(pplModel);
}
Model:
public class PersonDetailsModel : Person
{
public int? Person_Id { get; set; }
public string Person_First_Name { get; set; }
public string Person_Last_Name { get; set; }
public List<AddressDetails> Addresses
{
get
{
return _entities.SelectAddresses(Person_ID).Select(a => new AddressDetails
{
Address _Id = a.Address _Id
,
Address = a.Address
,
State = a.State
,
City = a.City
,
Zip_Code = a.Zip_Code
}
).ToList();
}
set
{
}
}
}
View
@using Personnel.ViewModel;
@using Personnel.Repository;
@model PersonModel.PersonDetailsModel
@using (Html.BeginForm("Address", "Person", FormMethod.Post, new { pplModel = Model }))
{
<div class="row can-totals">
<div class="table-responsive col-md-5">
<table class="table table-bordered table-condensed table-responsive address-tbl" id="tblAddrSummary" summary="Address Summary" style="padding-left: 10px;">
<thead>
<tr class="summary-header">
<th class="dt-head-center">#</th>
<th class="dt-head-center">Person Address</th>
</tr>
</thead>
<tbody>
@{
int index = 0;
}
@foreach (var item in Model.Addresses)
{
<tr>
<td class="addr-number">@String.Format("{0} - {1}", @item.Address_Id, @item.Address)</td>
<td class="addr-city">@Html.TextBox("city", Model.Addresses[index].City, new { @class = "form-control" })</td>
</tr>
index++;
}
</tbody>
</table>
</div>
</div>
<button type="submit" class="btn btn-primary">Save</button>
}