弹出部分视图在bootstrap模型弹出窗口中

时间:2016-11-30 11:02:27

标签: c# asp.net-mvc

@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",
                    })

这个动作链接我尝试在bootstrap模型中弹出局部视图,当我尝试编辑&除了模型状态无效外,保存它的工作原理 这是我的控制器代码

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 >

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

1 个答案:

答案 0 :(得分:0)

将操作的返回类型更改为Task<PartialView>