0

我有一个部分视图,必须显示下拉更改的记录。值正确出现,但未显示在 tex 框中。请帮忙。我的部分视图的代码如下所示

@using (Ajax.BeginForm("W2State", new AjaxOptions() { UpdateTargetId = "model", OnSuccess = "w2Updated", InsertionMode = InsertionMode.Replace, HttpMethod = "Post" } ))
{

    <fieldset id="currencyView" class="detailView">
        <table>
            <tr>
                <td style="width: 100px;">Select Agency </td> 
                <td> 
                @*@Html.DropDownListFor(model => model.ReportingAgencies, new SelectList(Model.ReportingAgencies, "SelectedAgency.AgencyGuid", "SelectedAgency.Name"), new { id = "dropDownReportAgencies" })*@
               @Html.DropDownListFor(model => model.ReportingAgencies, new SelectList(Model.ReportingAgencies, "SelectedAgency.AgencyGuid", "SelectedAgency.Name"), "--Select An Agency--", new { id = "dropDownReportAgencies" })
                </td>              
            </tr>
            <tr class="seperator"></tr>
            <tr class="seperator"></tr>

            <tr>
                <td style="width: 100px;">@Html.LabelFor(model => model.W2StateLocal.Wages)</td> 
                <td> @Html.TextBoxFor(model => model.W2StateLocal.Wages)</td> 
            </tr>
            <tr>
                <td style="width: 100px;">@Html.LabelFor(model => model.W2StateLocal.Tax)</td> 
                <td>@Html.TextBoxFor(model => model.W2StateLocal.Tax)</td> 
            </tr>
        </table>
        <div id="rightButtonControls">        
            @if (Model.IsEditable)
            {
                <button id="btnSave" value="save">Save</button>                
            }
        </div>    
    </fieldset>
}

        @Html.HiddenFor(model => model.CompanyId, new { id = "CompanyId" })
        @Html.HiddenFor(model => model.EmployeeId, new { id = "EmployeeId" })
        @Html.HiddenFor(model => model.FilingYear, new { id = "FilingYear" })


<script type="text/javascript">
    $(document).ready(function () {
        $("#divLoader").css('display', 'none');
        $('#dropDownReportAgencies').change(function () {

            var selectedAgency = $('#dropDownReportAgencies option:selected').val();


            var CompanyId = $('#CompanyId').val();

            var EmployeeId = $('#EmployeeId').val();

            var FilingYear = $('#FilingYear').val();

            var url = '@Url.Action("W2State", "W2Generation")';
            $.get(url, { agencyId: selectedAgency, companyId: CompanyId, employeeId: EmployeeId, filingYear: FilingYear },
                function (data) {
                            });



        });

    });
4

1 回答 1

1

您想通过 jQuery 从 mvc 中的下拉列表中获取文本...

您的代码是正确的,但只是缺少一些东西..您使用过

var selectedAgency = $('#dropDownReportAgencies option:selected').val();

但是你必须使用'text'而不是'val'..这意味着

var selectedAgency = $("#dropDownReportAgencies option:selected").text();

试试这个....

于 2012-12-10T05:38:16.493 回答