【问题标题】:Popup partial view in a bootstrap model popup在引导模式弹出窗口中弹出部分视图
【发布时间】:2016-12-05 14:22:41
【问题描述】:
@Html.ActionLink("edit", "Edit", "MedQuantityType", new { id = item.Med_quan_typeId }, new
                    {
                        @* Needed to link to the html of the modal*@
                        data_target = "#mymodel",
                        @* Tells the bootstrap javascript to do its thing*@
                        data_toggle = "modal",
                    })

这是我尝试在引导模型中弹出部分视图的操作链接,当我尝试编辑并保存它时它工作正常,除了模型状态无效 这是我的控制器代码

public async Task<ActionResult > Edit([Bind(Include = "Med_quan_typeId,Med_quan_type,Med_quantity")] Med_quantity_type med_quantity_type)
{
    if (ModelState.IsValid)
    {
        db.Entry(med_quantity_type).State = EntityState.Modified;
        await db.SaveChangesAsync();
        return RedirectToAction("Index");
    }

    return PartialView(med_quantity_type);
}

如果我的模型状态失败,控制器会返回部分视图,但它没有在 mymodel 中弹出,这是我的部分视图 cshtml 页面

<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                <span aria-hidden="true">&times;</span>
            </button>
            <h4 class="modal-title">Medicine Quantity Type - Edit</h4>
        </div>
        <div class="modal-body">
@using (Ajax.BeginForm("Edit", "MedQuantityType",
            new AjaxOptions
            {
                HttpMethod = "GET",
                InsertionMode = InsertionMode.Replace,
                UpdateTargetId = "mymodel"
            }))
            {
                @Html.AntiForgeryToken()

                <div class="form-horizontal">
                    @Html.ValidationSummary(true)
                    @Html.HiddenFor(model => model.Med_quan_typeId)

                    <div class="form-group">
                        <div class="col-md-3 col-md-offset-1">
                            @Html.LabelFor(model => model.Med_quan_type, new { @class = "control-label " })
                        </div>
                        <div class="col-md-6">
                            @Html.TextBoxFor(model => model.Med_quan_type, new { @class = "form-control", @id = "txtquantype"  })
                            @Html.ValidationMessageFor(model => model.Med_quan_type)
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-md-3 col-md-offset-1">
                            @Html.LabelFor(model => model.Med_quantity, new { @class = "control-label" })
                        </div>
                        <div class="col-md-6">
                            @Html.TextBoxFor(model => model.Med_quantity, new { @class = "form-control" })
                            @Html.ValidationMessageFor(model => model.Med_quantity)
                        </div>
                    </div>
                </div>

                <div class="modal-footer">
                            <input type="submit" value="Save" class="btn btn-success" id="btnsubmit" />                       
                            <button type="button" class="btn btn-danger" data-dismiss="modal">Cancel</button>
                    </div>

                <div ID ="popupform"class="popover">
                    <div class="alert-danger"> Please Fix The errors </div>

                </div>
            }
        </div>
    </div>
</div>

<script type="text/javascript">

    $(document).ready(function () {
        $(function () {
            debugger;
            // when the modal is closed
            $('#mymodel').on('hidden.bs.modal', function () {
                // remove the bs.modal data attribute from it
                $(this).removeData('bs.modal');
                // and empty the modal-content element
                $('#mymodel .modal-content').empty();
            });
        });
    });

    </script >

一旦控制器返回部分视图,请帮助任何人如何弹出部分视图

【问题讨论】:

  • 你能解释一下这个场景并说出究竟发生了什么,什么没有发生吗?你的问题有点不清楚

标签: c# asp.net-mvc


【解决方案1】:

Task&lt;ActionResult &gt;Task&lt;PartialViewResult&gt; 然后将您的 ActionLink 更改为 RenderPartial

它应该可以正常工作。

【讨论】:

    【解决方案2】:

    将您的操作的返回类型更改为Task&lt;PartialView&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-10
      • 2021-03-07
      • 2012-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-16
      相关资源
      最近更新 更多