• 批量添加代码,修改,删除控制器部分


     public class HomeController : Controller
        {
            bll s = new bll();引用

    //显示
            public ActionResult studentlist()
            {
                return View();
            }
            [HttpPost]
            public ActionResult StudentList1()
            {
                var result = new BLL.bll().Show();
                return Json(result);
            }

    添加
            [HttpPost]
            public JsonResult Studentadd(string a)
            {
                 a = a.TrimEnd('|');
                string[] ste = a.Split('|');
                if (ste == null||ste.Length==0)
                {
                    return Json(new
                    {
                        code=0,
                        msg="字符串异常"
                    });

                }
                else
                {
                    List<model> studentlist = new List<model>();
                    foreach (var item in ste)
                    {
                        string[] y = item.Split(',');
                        if (y != null || y.Length > 0)
                        {
                            model si = new model();
                            si.Sxuehao = y[0];
                            si.SNAME = y[1];
                            si.SAGE = y[2];
                            studentlist.Add(si);

                        }

                    }
                    var i = s.addlist(studentlist);
                    if (i > 0)
                    {
                        return Json(new
                        {
                            code = 1,
                            msg = "成功"
                        });
                    }
                    else
                    {
                        return Json(new
                        {
                            code = 0,
                            msg = "失败"
                        });

                    }

                }
               

            }

    删除
            public JsonResult del(int id)
            {
                var result = new BLL.bll().del(id);
                if (result > 0)
                {
                    return Json(1);
                }
                else
                {
                    return Json(0);
                }

            }

    修改
            public JsonResult update(model stu)
            {
                var result = s.uptate(stu);
                if (result > 0)
                {
                    return Json(new
                    {
                        code = 1,
                        msg = "成功"
                    });

                }
                else
                {
                    return Json(new
                    {
                        code = 0,
                        msg = "失败"
                    });
                }
            }
            public ActionResult About()
            {
                ViewBag.Message = "Your application description page.";

                return View();
            }

            public ActionResult Contact()
            {
                ViewBag.Message = "Your contact page.";

                return View();
            }
        }

  • 相关阅读:
    Winform 异步更新listbox
    Object-C
    易学易懂
    C# login with cookie and fiddler2
    开源 侧滑 和 Tab滑动翻页 控件
    Mysql Java type mapping
    jQuery滑动导航菜单
    js判断是移动端还是pc端
    设为主页和加入收藏
    原生javascript效果:无缝滚动
  • 原文地址:https://www.cnblogs.com/danhuangjun/p/7879229.html
Copyright © 2020-2023  润新知