标签:each lis form select for end list text rop
public ActionResult sanji()
{
var list = bl.sanji(0);
var linq = from i in list
select new SelectListItem
{
Text=i.name,
Value=i.id.ToString()
};
ViewBag.vb = linq;
return View();
}
//ajax方法
public string ajax(int aid)
{
var list = bl.sanji(aid);
var i = JsonConvert.SerializeObject(list);
return i;
}
*****************
<div>
@using (Html.BeginForm())
{
@Html.DropDownList("bid", ViewBag.vb as IEnumerable<SelectListItem>, "请选择")
<select id="Two">
<option>请选择</option>
</select>
<select id="Three">
<option>请选择</option>
</select>
}
</div>
///两遍
<script>
$("#bid").change(function () {
var Uid = $("#bid").val();
$.ajax({
url: "/Default/ajax?aid=" + Uid,
type: "get",
dataType: "Json",
success: function (data) {
$("#Two").empty().append("<option>请选择</option>");
$(data).each(function () {
var it = "<option value=‘" + this.id + "‘>" + this.name + "</option>";
$("#Two").append(it);
})}})})
</script>
标签:each lis form select for end list text rop
原文地址:https://www.cnblogs.com/gaoyuhui/p/10957317.html