• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# MVC 批量修改商品数据

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

Html:        //批量修改折扣

        $("#Confirm").click(function () {

        //    $.ajaxSettings.async = false;//取消异步

            var Category= $("#Category1").val();//获取商品类别

            var Brand=  $("#Brand1").val();//获取品牌

            var Season= $("#Season1").val();//获取季节

            var plggxszk = $("#plggxszk").val();//获取销售折扣

 

 

            //      $.getJSON("/JH/Commodity/MrketDiscount?Category=" + Category + "&Brand=" + Brand + "&Season=" + Season + "&Discount=" + plggxszk)

            $.ajax({

                url: "/JH/Commodity/MrketDiscount?Category=" + Category + "&Brand=" + Brand + "&Season=" + Season + "&Discount=" + plggxszk,

                type: "get",

                success: function (data) {

                    if (data.State) {

                        layer.msg(data.Text, { icon: 1, skin: "layui-layer-molv" });

 

 

                    }

                }

            })

        })

UIL:

  public ActionResult MrketDiscount(int Category, int Brand, int Season, decimal Discount)

        {

            //实例化返回的字符

            ReturnJson returnJson = new ReturnJson();

 

            var list = (from tbShangPin in myModels.JC_ShangPin

                        select new Discount

                        {

                            ShangPinTypeID = (int)(tbShangPin.ShangPinTypeID),

                            PinPaiID = (int)(tbShangPin.PinPaiID),

                            JiJieID = (int)(tbShangPin.JiJieID),

                            XiaoShozheko = (int)(tbShangPin.XiaoShozheko),

                            ShangPinID = tbShangPin.ShangPinID

                        }).ToList();

            //判断是否选中商品类型

            if (Category > 0)

            {

                list = list.Where(m => m.ShangPinTypeID == Category).ToList();

            }

            if (Brand > 0)

            {

                list = list.Where(m => m.PinPaiID == Brand).ToList();

            }

            if (Season > 0)

            {

                list = list.Where(m => m.JiJieID == Season).ToList();

            }

            if (list.Count > 0)

            {

                for (var i = 0; i < list.Count; i++)

                {

 

                    //声明变量 用于查询修改的商品ID

                    var a = list[i].ShangPinID;

                    JC_ShangPin ShangPin = (from tbSP in myModels.JC_ShangPin

                                            where tbSP.ShangPinID == a

                                            select tbSP).Single();

                    ShangPin.XiaoShozheko = Discount;

                    //list[i].XiaoShozheko = Discount;

                    myModels.Entry(ShangPin).State = System.Data.Entity.EntityState.Modified;

                    myModels.SaveChanges();

                }

            }

            returnJson.State = true;

            returnJson.Text = "批量更新折扣成功!";

            return Json(returnJson, JsonRequestBehavior.AllowGet);

        }

效果图:

说明:先查询出需要修改的数据有多少条,再根据查询出了的商品ID,用for循环循环修改数据就可以了。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap