【发布时间】:2014-01-23 15:36:47
【问题描述】:
我认为有这个脚本(this 是来源):
<script type="text/javascript" src="../../Scripts/jquery-1.7.1.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#state").prop("disabled", true);
$("#country").change(function () {
if ($("#country").val() != "Please select") {
var options = {};
options.url = "/companies/getbolag";
options.type = "POST";
options.data = JSON.stringify({ country: $("#country").val() });
options.dataType = "json";
options.contentType = "application/json";
options.success = function (states) {
$("#state").empty();
for (var i = 0; i < states.length; i++) {
$("#state").append("<option>" + states[i] + "</option>");
}
$("#state").prop("disabled", false);
};
options.error = function () { alert("Fel vid bolagshämtning!"); };
$.ajax(options);
}
else {
$("#state").empty();
$("#state").prop("disabled", true);
}
});
});
</script>
它会根据第一个下拉列表中的选择填充第二个下拉列表。级联下拉菜单。
此 HtmlHelper 触发脚本,但提交时省略值:
@Html.DropDownList("country", ViewData["kundLista"] as SelectList)
这个反之,它提交值但不触发脚本:
@Html.DropDownListFor(model => model.Kund, ViewData["kundLista"] as SelectList)
我需要它来触发脚本并提交值。我该怎么做?
【问题讨论】:
标签: c# asp.net-mvc-4 html-helper cascadingdropdown