【发布时间】:2016-06-28 15:04:11
【问题描述】:
我有一个模态弹出窗口,但我想对其进行模型状态验证。问题是如果存在模型状态错误,它会返回页面。如何将数据返回到弹出窗口,同时保持弹出窗口打开。这是我目前所拥有的:
[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 方法返回时保持打开状态。
【问题讨论】:
-
您是否尝试在表单中输入@Html.ValidationSummary(true)?
-
它没有用,但是谢谢。
标签: c# asp.net-mvc razor bootstrap-modal