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