首页 > 其他 > 详细

三级联动

时间:2019-05-31 21:57:15      阅读:88      评论:0      收藏:0      [点我收藏+]


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>

三级联动

原文:https://www.cnblogs.com/gaoyuhui/p/10957317.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!