三级联动

在数据访问中查询表中的Id来进行返回到显示获取Id

        public List<Birthplace> BindList(int id)
        {
            try
            {
              return db.Birthplaces.Where(a => a.Code == id).ToList();
            }
            catch (Exception)
            {

                throw;
            }
        }

在业务逻辑层调用数据访问层传过来的数据

public List<Birthplace> BindList(int id)
        {
            try
            {
                return dal.BindList(id);
            }
            catch (Exception)
            {

                throw;
            }
        }

在控制器中接收业务逻辑层传过来的数据

      public ActionResult BindList(int id)
        {
            try
            {
                return Json(bll.BindList(id),JsonRequestBehavior.AllowGet);
            }
            catch (Exception)
            {

                throw;
            }
        }

在试图中接收控制器返回的Json值

   let app = new Vue({
        el: "#app",
        data() {
            return {
                FromData: {
                    Job: "",
                    Ename: "",
                    Sex: true,
                    Tid: "0",
                    Salesman: "",
                    PhoneTel: "",
                    Email: "",
                    Plane: "",
                    Province: "0",
                    City: "",
                    County: "",
                    Birthday: "",
                    Remark: ""
                },
                Bumen: [],
                BidA: [],
                BidB: [],
                BidC:[]
            }
        },
        methods: {
            BindSelect() {
                axios.get('/Employee/BindSelect').then(res => {
                    this.Bumen = res.data;
                    this.Bumen.unshift({ "DId": "0", "DName": "请选择" });
                })
            },
            //省
            BindList() {
                axios.get('/Employee/BindList?id=' + 0).then(res => {
                    this.BidA = res.data;
                    this.BidA.unshift({ "Bid": "0", "Bname": "请选择" });
                })
            },
            //市
            BindListA() {
                this.BidB = [];
                this.BidC = [];
                var id = this.FromData.Province;
                axios.get('/Employee/BindList?id=' + id).then(res => {
                    this.BidB = res.data;
                    this.BidB.unshift({ "Bid": "0", "Bname": "请选择" });
                    this.FromData.City = this.BidB[0].Bid;
                })
            },
            //县
            BindListB() {
                this.BidC = [];
                var id = this.FromData.City;
                axios.get('/Employee/BindList?id=' + id).then(res => {
                    this.BidC = res.data;
                    this.BidC.unshift({ "Bid": "0", "Bname": "请选择" });
                    this.FromData.County = this.BidC[0].Bid;
                })
            },
            Add() {
                axios.post('/Employee/SubAdd', this.FromData).then(res => {
                    if (res.data > 0) {
                        alert('添加成功');
                        location.href = '/Employee/Show';
                    }
                    else {
                        alert('添加失败');
                    }
                })
            },
            Show() {
                location.href = '/Employee/Show';
            }
        },
        created: function () {
            this.BindSelect();
            this.BindList();
        }
    })

在表单中添加Id

            <td colspan="3">
                省
                <select v-model="FromData.Province" v-on:change="BindListA">
                    <option v-for="(item,index) in BidA" :value="item.Bid">{{item.Bname}}</option>
                </select>
                市
                <select v-model="FromData.City" v-on:change="BindListB">
                    <option v-for="(item,index) in BidB" :value="item.Bid">{{item.Bname}}</option>
                </select>
                县
                <select v-model="FromData.County">
                    <option v-for="(item,index) in BidC" :value="item.Bid">{{item.Bname}}</option>
                </select>
            </td>

 

上一篇:oracle listagg() 函数


下一篇:序列化、Socket、邮件、多线程