gpt4 book ai didi

c# - 提交后将 ActionResult 返回到模态弹出窗口

转载 作者:行者123 更新时间:2023-11-30 16:48:29 25 4
gpt4 key购买 nike

我有一个模态弹出窗口,但我想对其进行模型状态验证。问题是,如果存在模型状态错误,它会返回页面。如何将数据返回到弹出窗口,同时保持弹出窗口打开。这是我目前所拥有的:

[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 方法返回时让它保持打开状态。

最佳答案

讨厌回答我自己的问题,但我遇到了 id-10-T 错误。

我最初包括 jquery.validate.unobtrusive 而不是 jquery.unobtrusive-ajax。我现在都包含了它,它工作正常。

关于c# - 提交后将 ActionResult 返回到模态弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38079832/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com