我的视图中有一个下拉列表。下拉列表显示枚举值:
@Html.DropDownListFor(model => model.hobbyhome.HobbyDetailList.First().course, HobbyHomesWebApp.Utility.EnumList.ToSelectList(HobbyHomes.Model.Course.Advance, "Select Course"), "--Select Course--", new { @id="Course"}) <font color="red">*</font>
课程生成器
<div class="editor-field">
<select id="course" name="course"><option value="">--Select Course-- </option>
<option value="Basic">Basic Level</option>
<option value="Intermidiate">Intermidiate Level</option>
<option value="Advance">Advance Level</option>
</select> <font color="red">*</font>
</div>
var course = from Course c in Enum.GetValues(typeof(Course))
select new { ID = c, Name = c.ToString() };
ViewData["course"] = new SelectList(course, "ID", "Name");
涉及的输入选项是基本、中级和高级
我正在尝试根据所选值填充其他下拉列表:
$("#Course").change(function () {
var Hobbyid = $("#Hobby").val();
var Cid=$("#Course").val();
var urlHobbyhome = '@Url.Action("FetchStateByHobbyId")';
$.ajax({
type: "POST",
url: urlHobbyhome,
data: { id: Hobbyid,cid:Cid },
success: function (data) {
$('#State').empty();
$('#State')
.append($('<option>', { value: "0" })
.text("-- Select State --"));
$.each(data, function (key, value) {
$('#State')
.append($('<option>', { value: value.Value })
.text(value.Text));
});
}
});
我怎样才能做到这一点?