When I pass the view model to the method it crashes but it works with FormCollection or not passing anything to the onpost method.
Below is the code:
[HttpPost]
[AutoValidateAntiforgeryToken]
public ActionResult Update(CustomerInformation model)
{
if (ModelState.IsValid)
{
//save
var UpdateRecord = customerServices.Update(model);
if (UpdateRecord)
{
return RedirectToAction("Details");
}
}
}
@model Customer.Models.CustomerInformationDetails
@using Customer.Models.CustomerInformation
@{
var customerName = Model.Name;
ViewData["Title"] = customerName;
}
<h1>Edit information for @customerName</h1>
<hr />
@using (Html.BeginForm("Update",
"Customer",
FormMethod.Post))
{
<div class="form-group">
@Html.Label("Introduction", "Introduction:", htmlAttributes: new { @class = "control-label col-md-10" })
<div class="col-md-10">
@Html.EditorFor(model => model.Introduction, new { htmlAttributes = new { @class = "form-control" } })
</div>
</div>
<div class="form-group">
@Html.Label("Contact Person", "Contact Person:", htmlAttributes: new { @class = "control-label col-md-10" })
<div class="col-md-10">
@Html.EditorFor(model => model.ContactPerson, new { htmlAttributes = new { @class = "form-control" } })
</div>
</div>
<div class="form-group">
<input type="submit" value="Update" class="btn btn-primary"></input>
</div>
}