zoukankan      html  css  js  c++  java
  • 批量添加代码,修改,删除控制器部分

     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();
            }
        }

  • 相关阅读:
    @RenderBody()和@RenderSection()
    C# async await 死锁问题总结
    [小技巧]你真的了解C#中的Math.Round么?
    ASP.NET MVC
    api接口返回动态的json格式?我太难了,尝试一下 linq to json
    bootstrap-table表头固定,表内容不对齐的问题
    Windows下Nginx反向代理
    Windows下Nginx的启动停止等基本操作命令详解
    Asp.NET websocket,Asp.NET MVC 使用 SignalR 实时更新前端页面数据
    Asp.NET websocket,Asp.NET MVC 使用 SignalR 实现推送功能一(Hubs 在线聊天室)
  • 原文地址:https://www.cnblogs.com/danhuangjun/p/7879229.html
Copyright © 2011-2022 走看看