快活林资源网 Design By www.csstdc.com
本文实例为大家分享了MVC+jQuery.Ajax异步实现增删改查和分页的具体代码,供大家参考,具体内容如下
1、Model层代码
using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Collections.Generic; using MvcExamples; using System.Web.Mvc; namespace MvcExamples.Web.Models { public class StudentModels { /// <summary> /// 获取学生信息列表 /// </summary> public List<MvcExamples.Model.Student> StudentList { get; set; } /// <summary> /// 获取教工信息列表 /// </summary> public List<MvcExamples.Model.Teacher> TeacherList { get; set; } /// <summary> /// 获取学生信息列表(分页) /// </summary> public PagedList<MvcExamples.Model.Student> GetStudentList { get; set; } } }
2、View层代码
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MvcExamples.Web.Models.StudentModels>" %> <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"> Index </asp:Content> <asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server"> <script src="/UploadFiles/2021-04-02/jquery-1.4.2.min.js">3、Controller层代码
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 name="pi"></param> /// <param name="sclass"></param> /// <returns></returns> public ActionResult Index(int"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 name="no"></param> /// <param name="name"></param> /// <param name="sex"></param> /// <param name="birsthday"></param> /// <param name="sclass"></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 name="no"></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 name="no"></param> /// <param name="name"></param> /// <param name="sex"></param> /// <param name="birsthday"></param> /// <param name="sclass"></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 name="id"></param> /// <returns></returns> public ActionResult WindowData(int id) { JsonResult json = new JsonResult(); //这里给json数据(这里只是演示,下面数据是模拟的) json.Data = new { name = "张三", sex = "男" }; return json; } } }4、两个分页辅助类PagedList和MikePagerHtmlExtensions
PagedList辅助类
using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Collections.Generic; using System.Collections.Specialized; namespace System.Web.Mvc { public interface IPagedList { int TotalPage //总页数 { get; } int TotalCount { get; set; } int PageIndex { get; set; } int PageSize { get; set; } bool IsPreviousPage { get; } bool IsNextPage { get; } } public class PagedList<T> : List<T>, IPagedList { public PagedList(IQueryable<T> source, int"color: #800000">MikePagerHtmlExtensions辅助类using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Web.Mvc; using System.Web.Routing; using System.Text; namespace System.Web.Mvc { public static class MikePagerHtmlExtensions { #region MikePager 分页控件 public static string MikePager<T>(this HtmlHelper html, PagedList<T> data) { string actioinName = html.ViewContext.RouteData.GetRequiredString("action"); return MikePager<T>(html, data, actioinName); } public static string MikePager<T>(this HtmlHelper html, PagedList<T> data, object values) { string actioinName = html.ViewContext.RouteData.GetRequiredString("action"); return MikePager<T>(html, data, actioinName, values); } public static string MikePager<T>(this HtmlHelper html, PagedList<T> data, string action) { return MikePager<T>(html, data, action, null); } public static string MikePager<T>(this HtmlHelper html, PagedList<T> data, string action, object values) { string controllerName = html.ViewContext.RouteData.GetRequiredString("controller"); return MikePager<T>(html, data, action, controllerName, values); } public static string MikePager<T>(this HtmlHelper html, PagedList<T> data, string action, string controller, object values) { return MikePager<T>(html, data, action, controller, new RouteValueDictionary(values)); } public static string MikePager<T>(this HtmlHelper html, PagedList<T> data, RouteValueDictionary values) { string actioinName = html.ViewContext.RouteData.GetRequiredString("action"); return MikePager<T>(html, data, actioinName, values); } public static string MikePager<T>(this HtmlHelper html, PagedList<T> data, string action, RouteValueDictionary values) { string controllerName = html.ViewContext.RouteData.GetRequiredString("controller"); return MikePager<T>(html, data, action, controllerName, values); } public static string MikePager<T>(this HtmlHelper html, PagedList<T> data, string action, string controller, RouteValueDictionary valuedic) { int start = (data.PageIndex - 5) >= 1 "<div class=\"mike_mvc_pager\">"); if (data.IsPreviousPage) { vs["pi"] = 1; builder.Append(Html.LinkExtensions.ActionLink(html, "首页", action, controller, vs, null)); builder.Append(" "); vs["pi"] = data.PageIndex - 1; builder.Append(Html.LinkExtensions.ActionLink(html, "上一页", action, controller, vs, null)); builder.Append(" "); } for (int i = start; i <= end; i++) //前后各显示5个数字页码 { vs["pi"] = i; if (i == data.PageIndex) { builder.Append("<font class='thispagethis'>" + i.ToString() + "</font> "); } else { builder.Append(" "); builder.Append(Html.LinkExtensions.ActionLink(html, i.ToString(), action, controller, vs, null)); } } if (data.IsNextPage) { builder.Append(" "); vs["pi"] = data.PageIndex + 1; builder.Append(Html.LinkExtensions.ActionLink(html, "下一页", action, controller, vs, null)); builder.Append(" "); vs["pi"] = data.TotalPage; builder.Append(Html.LinkExtensions.ActionLink(html, "末页", action, controller, vs, null)); } builder.Append(" 每页" + data.PageSize + "条/共" + data.TotalCount + "条 第" + data.PageIndex + "页/共" + data.TotalPage + "页 </div>"); return builder.ToString(); } #endregion } }效果图:
5、源码下砸:jQuery.Ajax异步实现增删改查和分页
以上就是本文的全部内容,希望对大家的学习有所帮助。
快活林资源网 Design By www.csstdc.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
快活林资源网 Design By www.csstdc.com
暂无评论...
P70系列延期,华为新旗舰将在下月发布
3月20日消息,近期博主@数码闲聊站 透露,原定三月份发布的华为新旗舰P70系列延期发布,预计4月份上市。
而博主@定焦数码 爆料,华为的P70系列在定位上已经超过了Mate60,成为了重要的旗舰系列之一。它肩负着重返影像领域顶尖的使命。那么这次P70会带来哪些令人惊艳的创新呢?
根据目前爆料的消息来看,华为P70系列将推出三个版本,其中P70和P70 Pro采用了三角形的摄像头模组设计,而P70 Art则采用了与上一代P60 Art相似的不规则形状设计。这样的外观是否好看见仁见智,但辨识度绝对拉满。
更新日志
2025年01月16日
2025年01月16日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]