MVC+jQuery.Ajax异步实现增删改查和分页(2)

分页标题#e#

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web.Mvc.Ajax; namespace MvcExamples.Web.Controllers { public class StudentController : Controller { // // GET: /Student/ MvcExamples.BLL.Student _Student = new MvcExamples.BLL.Student(); MvcExamples.BLL.Teacher _Teacher = new MvcExamples.BLL.Teacher(); /// <summary> /// 演示 /// </summary> /// <param></param> /// <param></param> /// <returns></returns> public ActionResult Index(int? pi, string sclass) { int PageIndex = pi ?? 1; int PageSize = 5; string sClass = sclass == null ? "95031" : sclass; MvcExamples.Web.Models.StudentModels _StudentModels = new MvcExamples.Web.Models.StudentModels(); _StudentModels.StudentList = _Student.GetModelList("sclass=" + sClass); _StudentModels.TeacherList = _Teacher.GetModelList("tsex='男'"); _StudentModels.GetStudentList = new PagedList<MvcExamples.Model.Student>(_Student.GetModelList("sclass=" + sClass).AsQueryable(), PageIndex, PageSize); return View(_StudentModels);//返回一个Model } /// <summary> /// 修改学生信息 /// </summary> /// <param></param> /// <param></param> /// <param></param> /// <param></param> /// <param></param> /// <returns></returns> public ActionResult UpdateStudent(string no, string name, string sex, string birsthday, string sclass) { MvcExamples.Model.Student _student = new MvcExamples.Model.Student(); _student.sno = no; _student.sname = name; _student.ssex = sex; _student.sbirthday = Convert.ToDateTime(birsthday); _student.sclass = sclass; _Student.Update(_student); JsonResult json = new JsonResult(); json.Data = new { result = "true" }; return json; } /// <summary> /// 删除学生信息 /// </summary> /// <param></param> /// <returns></returns> public ActionResult DeleteStudent(string no) { bool IsDelete= _Student.Delete(no); JsonResult json = new JsonResult(); return json; if (IsDelete) { json.Data = new { result = "true" }; } else { json.Data = new { result ="false" }; } return json; } /// <summary> /// 添加学生信息 /// </summary> /// <param></param> /// <param></param> /// <param></param> /// <param></param> /// <param></param> /// <returns></returns> public ActionResult AddStudent(string no, string name, string sex, string birsthday, string sclass) { MvcExamples.Model.Student _student = new MvcExamples.Model.Student(); _student.sno = no; _student.sname = name; _student.ssex = sex; _student.sbirthday = Convert.ToDateTime(birsthday); _student.sclass = sclass; _Student.Add(_student); JsonResult json = new JsonResult(); json.Data = new { result = "true" }; return json; } /// <summary> /// 提供弹出窗口的数据 /// </summary> /// <param></param> /// <returns></returns> public ActionResult WindowData(int id) { JsonResult json = new JsonResult(); //这里给json数据(这里只是演示,下面数据是模拟的) json.Data = new { name = "张三", sex = "男" }; return json; } } }

4、两个分页辅助类PagedList和MikePagerHtmlExtensions

PagedList辅助类

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wzpsyf.html