2012-11-27 78 views
0

我有一個局部視圖,必須顯示下拉更改的記錄。值正確,但它沒有顯示在tex框中。請幫忙。我的局部視圖的代碼看起來像下面如何從MVC中的下拉菜單中顯示文本

@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) { 
          }); 



     }); 

    }); 
+0

代碼是否在下拉列表中加載,而不是文本框?你能否提供更多細節? –

回答

1

你想從通過jQuery的MVC下拉文字...

你的代碼是正確的,但只是失去了一些東西。你用

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

但不是 'VAL' 你必須使用 '文本' ..這意味着

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

試試這個....

相關問題