我有一个模态弹出窗口,但我想对它进行模型状态验证。问题是,如果存在模型状态错误,则返回页面。如何将数据返回到弹出窗口,保持弹出窗口打开。以下是我到目前为止的情况:
[HttpPost]
public ActionResult SaveProject( AddstuffViewModel model )
{
if (!ModelState.IsValid)
{
return PartialView("_Addstuff", model);
}
}
@model Models.AddStuffViewModel
@using (Ajax.BeginForm(
"SaveProject", "Projects",
new AjaxOptions {
HttpMethod = "POST",
},
new {
id = "FormName",
role = "form" }
))
{
<div class="panel-heading projectModal-heading">
<h4 class="panel-title">Add stuff </h4>
</div>
<div class="panel-body">
<p class="group">
<div class="form-group">
@Html.LabelFor(m => m. Stuffs.Name, new { @class = "control-label" })
@Html.TextBoxFor(m => m.Stuffs.Name, new { @class = "form-control", @id = "InputName", @placeholder = "Stuffs Name" })
@Html.ValidationMessageFor(m => m.Stuffs.Name, "", new { @class = "text-danger" })
</div>
<div class="form-group">
@Html.LabelFor(m => m.Stuffs.Description, new { @class = "control-label" })
@Html.TextBoxFor(m => m.Stuffs.Description, new { @class = "form-control", @id = "InputDescription", @placeholder = "Description" })
@Html.ValidationMessageFor(m => m.Stuffs.Description, "", new { @class = "text-danger" })
</div>
<div class="form-group">
@Html.LabelFor(m => m.Stuffs.Url, new { @class = "control-label" })
@Html.TextBoxFor(m => m.Stuffs.Url, new { @class = "form-control", @id = "InputUrl", @placeholder = "Url" })
@Html.ValidationMessageFor(m => m.Stuffs.Url, "", new { @class = "text-danger" })
</div>
</div>
</p>
</div>
<div class="panel-footer">
<input type="submit" value="stuff" class="btn btn-default" />
</div>
}
模态打开正常,所有数据都正确填充。我只想在SaveProject方法返回时保持打开状态。
答案 0 :(得分:2)
讨厌回答我自己的问题,但我有一个id-10-T错误。
我最初包含了jquery.validate.unobtrusive而不是jquery.unobtrusive-ajax。我现在包括两个都很好。