繁体   English   中英

将ID的值从局部视图传递到主视图

[英]Passing value of ID from partial view To the main View

**控制器代码**

我在局部视图中有以下代码,其ID为loan_no

<html>
<head>


</head>
<body>
    <table class="label-primary" style="width:110%" id="loan_type">
        <tr>
            <td>
                <div class="floatleft" style="height:50px">
                    <div class="label" style="font-size:inherit">Loan Name:</div>

                    <strong>
                        @Html.DropDownList("loan_code",
                                                        (SelectList)ViewBag.loanTypes, "--Select Loan Product--",
                                                        htmlAttributes:new { required = "required",@class = "form-control chosen mandatory",
                                                            @id ="loan_code"})
                        @Html.ValidationMessage("loan_code", "", new { @class = "text-danger" })
                    </strong>
                </div>
            </td>
            <td>
                <div class="label" style="font-size:inherit">*Loan No:</div>
                <span id="loan_no"></span>
            </td>

        </tr>

    </table>
</body>
</html>

主视图代码这是视图中的代码,JavaScript函数savePayslipInfo发出Ajax请求。我需要将部分视图的id'loan_no'中的值传递给该主视图。

<script type="text/javascript">

    function savePayslipInfo() {

        var current_loan_number = $("#loan_no").val();//id is from the partial View posted on the code above
        console.log(current_loan_number)
        $.ajax({
            type: "POST",
            url: "http://localhost:1079/loanapplication/save_Payslip_Info/?loan_no" + current_loan_number,
            data: {
                loan_no: $("#loan_no").val(),
                basic_salary: $("#basic_salary").val(),
                house_allowance: $("#house_allowance").val(),
                other_allowance: $("#other_allowance").val(),
                other_payment: $("#other_payment").val(),
                total_deduction: $("#total_deduction").val(),

            },
            success: function () {
                $('#msg').html("Payslip info saved successfully").fadeIn('slow');
                $('#msg').delay(4000).fadeOut('slow');
            }

        });
    }
</script>

因为我试图将html span标签中的InnerText值传递给Ajax中的url,所以我使用了javascript'document.getElementById(“ loan_no”)。innerText;' 然后像这样传递它:

$.ajax({
            type: "POST",
            url: "http://localhost:1079/loanapplication/save_Payslip_Info/?loan_no" + document.getElementById("loan_no").innerText,
            data: {
                loan_no: document.getElementById("loan_no").innerText,
                basic_salary: $("#basic_salary").val(),
                house_allowance: $("#house_allowance").val(),
                other_allowance: $("#other_allowance").val(),
                other_payment: $("#other_payment").val(),
                total_deduction: $("#total_deduction").val(),

            },
            success: function () {
                $('#msg').html("Payslip info saved successfully").fadeIn('slow');
                $('#msg').delay(4000).fadeOut('slow');
            }

        });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM