如何解决将 ViewModel 传递给控制器时应用程序崩溃
[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 语句之外。
目前如果失败了就没有什么可返回的了。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。