如何在两个不同的回发中保留editorfor价值

时间:2018-10-10 09:02:55

标签: javascript jquery asp.net-mvc modal-dialog

美好的一天。

我有3个面板。每个面板中都有多个EditorFor,一个是可编辑的,其余是只读的。当用户单击可编辑的EditorFor时,将弹出一个带有客户表的模式。单击选择按钮后,将根据表中的值填充面板中的EditorFor。

问题是我有这两个面板,每个面板分配了不同的模式。如果我从第一个模式的第一个表中选择一个值,则将填充第一个面板,但是当我从第二个模式的第二个表中选择一个值时,第一个面板的数据将丢失,只有第二个面板具有值。

这里是sample

控制器

public ActionResult DroppingApplication(string Petname, string Petaddress, string Objid, string Opid, string Opname, string Mno, string Franid)
{
   ViewBag.DrpReason = new SelectList(db.tbl_DroppingReason, "id", "Reason");
   ViewBag.Petname = Petname;
   ViewBag.Petaddress = Petaddress;
   ViewBag.Petid = Objid;

   ViewBag.Opname = Opname;
   ViewBag.Opid = Opid;
   ViewBag.Fno = Franid;
   ViewBag.Mno = Mno;

   return View();
}

删除应用程序视图

@model iVehicles.ViewModel.DropViewModel

<div>
    @using (Html.BeginForm("Index", "Application", FormMethod.Post, new { @id = "submitFormFirst" }))
    {
        @Html.AntiForgeryToken()

        <div class="form-horizontal">

            @Html.ValidationSummary(true, "", new { @class = "text-danger" })
            <br />
            <br />
            <div class="col-md-6 col-md-offset-3">
                @* ----------------------------------------------------------------
                     PETITIONER
                    ----------------------------------------------------------------
                *@

                <div class="panel panel-primary col-md-6 col-md-offset-3">
                    <div class="panel-heading"><h4>PETITIONER INFORMATION</h4></div>
                    <div class="panel-body">

                        <div class="form-group">
                            @Html.EditorFor(model => model.petitioner_id, new { htmlAttributes = new { @class = "form-control hidden",  @readonly = "readonly", @id = "objid", @Value = ViewBag.Objid } })
                        </div>

                        <div class="form-group">
                            @Html.LabelFor(model => model.petitioner_name, htmlAttributes: new { @class = "control-label" })
                            @Html.EditorFor(model => model.petitioner_name, new { htmlAttributes = new { @class = "form-control", placeholder = @Html.DisplayNameFor(m => m.petitioner_name), @id = "petname" , @Value = ViewBag.Petname, data_toggle = "modal", data_target = "#myModal", data_backdrop = "static", data_keyboard = "false" } })
                            @Html.ValidationMessageFor(model => model.petitioner_name, "", new { @class = "text-danger" })
                        </div>

                        <div class="form-group">
                            @Html.LabelFor(model => model.petitioner_address, htmlAttributes: new { @class = "control-label" })
                            @Html.EditorFor(model => model.petitioner_address, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly", placeholder = @Html.DisplayNameFor(m => m.petitioner_address), @id = "petaddress", @Value = ViewBag.Petaddress } })
                            @Html.ValidationMessageFor(model => model.petitioner_address, "", new { @class = "text-danger" })
                        </div>
                    </div>
                </div>


                @* ----------------------------------------------------------------
                    PETITIONEE
                    ----------------------------------------------------------------
                *@               
                <div class="panel panel-primary col-md-6 col-md-offset-3">
                    <div class="panel-heading"><h4>PETITIONEE INFORMATION</h4></div>
                    <div class="panel-body">

                        <div class="form-group">
                            @Html.EditorFor(model => model.operator_id, new { htmlAttributes = new { @class = "form-control hidden", @readonly = "readonly", @id = "opid", @Value = ViewBag.Opid } })
                        </div>

                        <div class="form-group">
                            @Html.EditorFor(model => model.franchise_id, new { htmlAttributes = new { @class = "form-control hidden", @readonly = "readonly", @id = "franid", @Value = ViewBag.Fno } })
                        </div>

                        <div class="form-group">
                            @Html.LabelFor(model => model.operator_name, htmlAttributes: new { @class = "control-label" })
                            @Html.EditorFor(model => model.operator_name, new { htmlAttributes = new { @class = "form-control", placeholder = @Html.DisplayNameFor(m => m.operator_name), @id = "opname", @Value = ViewBag.Opname, data_toggle = "modal", data_target = "#myModal2", data_backdrop = "static", data_keyboard = "false" } })
                            @Html.ValidationMessageFor(model => model.operator_name, "", new { @class = "text-danger" })
                        </div>

                        <div class="form-group">
                            @Html.LabelFor(model => model.motor_no, htmlAttributes: new { @class = "control-label" })
                            @Html.EditorFor(model => model.motor_no, new { htmlAttributes = new { @class = "form-control", @readonly = "readonly", placeholder = @Html.DisplayNameFor(m => m.motor_no), @id = "mno", @Value = ViewBag.Mno } })
                            @Html.ValidationMessageFor(model => model.motor_no, "", new { @class = "text-danger" })
                        </div>

                    </div>
                </div>

                <div class="col-md-6 col-md-offset-3">
                    <input type="submit" value="Next" id="submitBtn" class="btn btn-success" />
                </div>
            </div>
        </div>
    }
</div>         

@*--------------------------------------MODAL 1------------------------------------------------*@

<div class="modal fade" id="myModal" aria-labelledby="myModalLabel" aria-hidden="true">
    <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" id="myModalLabel">Modal title</h4>
            </div>
            <div class="modal-body">
                @{Html.RenderAction("PayerList", "Dropped");}

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

@*--------------------------------------MODAL 2------------------------------------------------*@

<div class="modal fade" id="myModal2" aria-labelledby="myModalLabel" aria-hidden="true">
    <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" id="myModalLabel">Modal title</h4>
            </div>
            <div class="modal-body">
                @{Html.RenderAction("OperatorList", "Dropped");}

            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
            </div>
        </div>
    </div>
</div>

PayList部分视图

<td>
   <a href="@Url.Action("DroppingApplication","Dropped",new { Objid= @item.objid, Petname=@item.name, Petaddress=@item.primaryaddress })"class="button" onclick="SetName();">Select</a>
</td>

@section Scripts{
<script type="text/javascript">
function SetName() {
    var txtName = window.opener.document.getElementById("petname");
    var txtAddress = window.opener.document.getElementById("petaddress");
    var txtObjid = window.opener.document.getElementById("objid");

        txtName.value = document.getElementById('Petname').value;
        txtAddress.value = document.getElementById('Petaddress').value;
        txtObjid.value = document.getElementById('Objid').value;
}
</script>
}

OperatorList部分视图

<td>
   <a href="@Url.Action("DroppingApplication","Dropped",new { Opid= @item.operator_id, Opname= @item.operator_id, Franid=@item.franchise_id, Mno=@item.motor_no })" class="button" onclick="SetName();">Select</a>
</td>

@section Scripts{
<script type="text/javascript">
function SetName() {
    var txtOpname = window.opener.document.getElementById("opname");
    var txtOpid = window.opener.document.getElementById("opid");
    var txtMno = window.opener.document.getElementById("mno");
    var txtFranid = window.opener.document.getElementById("franid");

    txtOpname.value = document.getElementById('Opname').value;
    txtOpid.value = document.getElementById('Opid').value;
    txtMno.value = document.getElementById('Mno').value;
    txtFranid.value = document.getElementById('Franid').value;
}
    </script>
}

谢谢。

0 个答案:

没有答案
相关问题