3
我有一個模式彈出,但我想對它做模型狀態驗證。問題是如果有模型狀態錯誤,它會返回頁面。如何將數據返回到彈出窗口,保持彈出窗口打開。這是我到目前爲止:返回ActionResult提交後提交模式彈出
[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)? –
它沒有工作,但謝謝。 –