.net core web程序增删改查

本文介绍了使用.NET Core进行Web程序的CRUD操作,详细展示了控制器的代码实现,包括模糊查询、添加、修改和删除功能。同时,提到了在index视图页中如何导入和编写页面及script代码,以及添加页面的HTML结构设计。虽然修改页面类似添加,但需额外处理编号,具体内容未详述。
摘要由CSDN通过智能技术生成

控制器代码`:


private readonly GoodsManagementContext _context;//声明全局变量`:
 public GoodsController(GoodsManagementContext context)
        {
   
            _context = context;//给全局变量赋值
        }
        public async Task<IActionResult> Index()//首页展示数据
        {
   
            ViewData["class"] = _context.TbClass.ToList();//给下拉列表赋值
            var list = _context.Goods.ToListAsync();
            return View(await list);
        }

开始模糊查询和添加修改删除

/// <summary>
        /// 根据条件查询数据
        /// </summary>
        /// <param name="GoodsName"></param>
        /// <param name="IsHot"></param>
        /// <param name="ClassId"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Index(string GoodsName = "", string IsHot = "all", int ClassId = 0)
        {
   
            bool bo = false;
            if (IsHot == "true")
            {
   
                bo = true;
            }
            else if (IsHot == "false")
            {
   
                bo = false;
            }
            ViewData["class"] = _context.TbClass.ToList();//给下拉列表赋值
            var list = _context.Goods.Where(gc => (gc.ClassName.Contains(GoodsName) || GoodsName == "") && (gc.ClassId == ClassId || ClassId == 0) && (IsHot == "all" || gc.IsHot == bo)).ToListAsync();
            return View(await list);
        }

        public IActionResult add()//添加数据视图页
        {
   
            ViewBag.ClassId = new SelectList(_context.TbClass.ToList(), "ClassId", "ClassName", 0);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

苓一在学习

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值