我在mvc 4中创建了一个Ajax表单,就像那样
@using (Ajax.BeginForm("Create", ajaxOptions: new AjaxOptions { UpdateTargetId = "updatedDiv", OnFailure = "OnFailure" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary()
<div id="Errors" class="block">
</div>
@*<div class="block width-50">
<div class="input-group" style="direction: ltr">
<input type="text" class="form-control">
<span class="input-group-addon">Incoming No</span>
</div>
</div>*@
<div class="block" id="item-guarantee">
@Html.RadioButtonFor(m => m.CorrespondenceSideId, 1, new { @checked = "checked" })<label class="label-style">@Global.CorrespondenceSide_Internal</label>
@Html.RadioButtonFor(m => m.CorrespondenceSideId, 2)<label class="label-style">@Global.CorrespondenceSide_External</label>
@Html.ValidationMessageFor(m => m.CorrespondenceSideId)
</div>
<div class="block">
<div class="input-group">
@Html.Label(Global.Correspondence_CorrespondenceNo)
@Html.EditorFor(m => m.CorrespondenceNo)
@Html.ValidationMessageFor(m => m.CorrespondenceNo)
</div>
</div>
<div class="block">
<div class="input-group">
@Html.Label(Global.Correspondence_IncomingNo)
@Html.EditorFor(m => m.IncomingNo)
@Html.ValidationMessageFor(m => m.IncomingNo)
</div>
</div>
}
这是控制器
public ActionResult Create(Correspondence model)
{
ViewBag.BoxType = (Enum_BoxType)model.BoxTypeId;
ViewBag.CorrespondenceTypesList = this.Factory.Get<CorrespondenceTypesService>()
.GetAsListItems(this.CurrentLanguage);
ViewBag.AssignmentSidesList = this.Factory.Get<AssignmentSidesService>()
.GetAsListItems(this.CurrentLanguage);
ViewBag.IncomingSidesList = this.Factory.Get<IncomingSidesService>()
.GetAsListItems(this.CurrentLanguage);
ViewBag.Lookup_BoxTypes = this.Factory.Get<BoxTypesServices>().GetAsListItems(this.CurrentLanguage, (int)ViewBag.BoxType);
if (!ModelState.IsValid) return PartialView("_CreatePartial", model);
this.Factory.Get<CorrespondencesService>().AuthorizedAdd(model);
var AllCorrespondences = this.Factory.Get<CorrespondencesService>().GetAll(correspondence => correspondence.Date, (Enum_BoxType)model.BoxTypeId).ToList();
return new View("Index", AllCorrespondences.ToPagedList(1, 5));
}
现在,当我返回PartialView("_CreatePartial", model);
并且模型返回时出现模型错误时,错误不会出现在&#39; validationsummary()&#39;在部分