【问题标题】:Return ActionResult to modal popup after submit提交后将 ActionResult 返回到模式弹出窗口
【发布时间】: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


【解决方案1】:

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

我最初包含 jquery.validate.unobtrusive 而不是 jquery.unobtrusive-ajax。我将两者都包括在内,现在效果很好。

【讨论】:

    猜你喜欢
    • 2017-03-08
    • 1970-01-01
    • 2020-08-19
    • 1970-01-01
    • 1970-01-01
    • 2012-01-26
    • 1970-01-01
    • 2017-09-17
    • 1970-01-01
    相关资源
    最近更新 更多