我在视图中有2个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 :(得分: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
}
答案 1 :(得分:0)
在我的项目中,我这样做
我用我的国家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.');
}
});
}
我认为这会对你有所帮助......