ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

三级联动

2021-08-26 21:35:38  阅读:149  来源: 互联网

标签:res id Bname 联动 Employee BidC BindList 三级


在数据访问中查询表中的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>

 

标签:res,id,Bname,联动,Employee,BidC,BindList,三级
来源: https://www.cnblogs.com/ss121166/p/15191562.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有