2012-10-01 18 views
0

我在視圖dropdownlistfor ..他們每個人都可能會導致回傳 我想要得到的一個名稱時,回發我如何確定在mvc3中導致回發的dropdownlist?

   <tr> 
       <td> 
        <label> 
         Owner</label> 
       </td> 
       <td> 
        @Html.DropDownListFor(m => m.OwnerId, new System.Web.Mvc.SelectList(Model.CallForPaperJournalOwnersList, "OwnerId", "Owner"), new { onchange = "submit();" }) 
       </td> 
      </tr> 
      <tr> 
       <td> 
        <label> 
         Journal Code:</label> 
       </td> 
       <td> 
        @Html.DropDownListFor(m => m.JournalCode, new System.Web.Mvc.SelectList(Model.JournalsWithCallForPaperHtmlList, "JournalCode", "JournalCode"), new { onchange = "submit();" }) 

       </td> 
      </tr> 

回答

0

在這種情況下......我會用一個id:

<tr> 
       <td> 
        <label> 
         Owner</label> 
       </td> 
       <td> 
        @Html.DropDownListFor(m => m.OwnerId, new System.Web.Mvc.SelectList(Model.CallForPaperJournalOwnersList, "OwnerId", "Owner"), new { id = "btnsave2" }) 
       </td> 
      </tr> 
      <tr> 
       <td> 
        <label> 
         Journal Code:</label> 
       </td> 
       <td> 
        @Html.DropDownListFor(m => m.JournalCode, new System.Web.Mvc.SelectList(Model.JournalsWithCallForPaperHtmlList, "JournalCode", "JournalCode"), new { id= "btnchange2" }) 

       </td> 
      </tr> 

,並調用ID

 $('#btnsave1').click(function (event) { 
//do stuff here 
} 

如果你想要做一個以上的DDL操作不使用onclick ..用途:

@Html.DropDownListFor(m => m.OwnerId, new System.Web.Mvc.SelectList(Model.CallForPaperJournalOwnersList, "OwnerId", "Owner"), new { @class = "myclass" }) 

和jQuery的只是去:

$('.myclass').click(function (event) { 
//do stuff here 
} 
0

在我的項目我正在做這樣的

我填我的狀態dropdownl與國家ID這樣

這是我的下拉列表

@Html.DropDownListFor(model => model.CountryId, new SelectList(Model.Countries, "ID", "Name"), "select", new { @ID = "ddlCountry", @class = "text", Style = "width: 150px;", onchange = "javascript:cascadingdropdown();" }) 

我創建了一個JavaScript函數,這樣它的下面

<script type="text/javascript"> 
    function cascadingdropdown() {    
     var countryID = $('#countryID').val(); 
     $.ajax({ 
      url: "/City/State", 
      dataType: 'json', 
      data: { countryId: countryID }, 
      success: function (data) { 
       $("#stateID").empty(); 
       $("#stateID").append("<option value='0'>--Select State--</option>"); 
       $.each(data, function (index, optiondata) { 
        alert(optiondata.StateName); 
        $("#stateID").append("<option value='" + optiondata.ID + "'>" + optiondata.StateName + "</option>"); 
       }); 
      }, 
      error: function() { 
       alert('Faild To Retrieve states.'); 
      } 

     }); 
    } 

我認爲這將有助於你...