我的jquery是这样的
<script type="text/javascript">$(document).ready(function(){
$("#drpId").change(function(e) {
firstDDLValue = $("#drpId").val();
$.post('@Url.Action("GetDataForSecond", "Login")', { fstValue: firstDDLValue }, function (e) {
var select = $("#secondDDLID");
select.empty();
$.each(result, function (index, Data) {
select.append($('<option/>', {
value: result.Value,
}));
});
});
});
});
我的控制器代码是
public JsonResult GetDataForSecond(string fstValue)
{
Domain obj = new Domain();
var data = obj.LoadSubDomain(fstValue); return Json(data, JsonRequestBehavior.AllowGet);
在数据中,我得到了第二个下拉列表的所有值,但考虑到它没有约束力。我的视图代码就是这样
<div class="editor-field">
@{
var data = ViewBag.MyData;
<select name="drpId" id="drpId">
<option value="yourvalue">Select DomainName </option>
@foreach (var te in data)
{
<option>@te.DomainName</option>
}
</select>
}
@Html.ValidationMessageFor(model => model.DomainName)
</div>
<div class="editor-field">
<select name="secondDDLID" id="secondDDLID">
<option value="yourvalue"></option>
</select>
</div>