C# 如何确定mvc3中哪个DropDownlostFor导致回发?
我在视图中有两个下拉列表。。它们中的每一个都可能导致回发 我想在我发回邮件时得到那个人的名字C# 如何确定mvc3中哪个DropDownlostFor导致回发?,c#,asp.net-mvc-3,C#,Asp.net Mvc 3,我在视图中有两个下拉列表。。它们中的每一个都可能导致回发 我想在我发回邮件时得到那个人的名字 <tr> <td> <label> Owner</label> </td> <td>
<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>
所有者
@Html.DropDownListFor(m=>m.OwnerId,new System.Web.Mvc.SelectList(Model.CallForPaperJournalOwnersList,“OwnerId”,“Owner”),new{onchange=“submit();”})
日记账代码:
@DropDownListFor(m=>m.JournalCode,new System.Web.Mvc.SelectList(Model.journalswithcallforpaperhtmlist,“JournalCode”,“JournalCode”),new{onchange=“submit();”})
在这种情况下。。。我会使用一个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>
如果要对多个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
}
在我的项目中,我就是这样做的 我用国家身份证填写我的州名单 这是我的下拉列表
@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.');
}
});
}
函数cascadingdropdown(){
var countryID=$('#countryID').val();
$.ajax({
url:“/城市/州”,
数据类型:“json”,
数据:{countryId:countryId},
成功:功能(数据){
$(“#stateID”).empty();
$(“#stateID”).append(“--Select State--”);
$.each(数据、函数(索引、选项数据){
警报(optiondata.StateName);
$(“#stateID”).append(“+optiondata.StateName+”);
});
},
错误:函数(){
警报(“检索状态失败”);
}
});
}
我想这会帮助你。。。
<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.');
}
});
}