问题描述
[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>
}
解决方法
添加
return View(model)
在 if 语句之外。
目前如果失败了就没有什么可返回的了。