Asp.net MVC5 局部刷新 Ajax
2018-06-22 06:11:57来源:未知 阅读 ()
先安装改js包
主页面的代码主页文件代码Index.cshtml
@model IEnumerable<Nineksy.Models.LabTable> @{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_MainView.cshtml"; } <div class="mrcTable"> @using (Ajax.BeginForm("GetrListLabResult", "TeaBespeakLab", new AjaxOptions { InsertionMode = InsertionMode.ReplaceWith, HttpMethod = "Get", OnFailure = "searchFailed", LoadingElementId = "load_ajax", UpdateTargetId = "mrcTableContent" })) { <div class="mrcTableNav"> <input type="text" name="name" id="" placeholder=" 实验室名称" class="mrcTableNav-input"> <button name="" id="btSelect" class="btn btn-success" type="submit"><i class="Hui-iconfont"></i> 搜资讯</button> </div> } <div id="load_ajax" style="display: none"> 正在加载......... </div> <div class="mrcTableContent" id="mrcTableContent"> </div> </div> 主页面的后台代码
public ActionResult Index(int page=1) { LabListVm model = new LabListVm { LabListTables = _db.LabTables.OrderBy(d => d.LabId).Skip((page - 1) * _pageSize).Take(_pageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = _pageSize, TotalItems = _db.DeviceTables.Count() } }; return View(model); }
后台用到的类
public class LabListVm { public static int PageSize = int.Parse(ConfigurationManager.AppSettings["pageSize"]); public IEnumerable<LabTable> LabListTables { get; set; } public PagingInfo PagingInfo { get; set; } }
public class LabTable { public int LabTableId { get; set; } public string LabId { set; get; } public string LabName { set; get; } public string LabAddress { set; get; } public string LabStatus { set; get; } public int? LabUseNum { set; get; } public string LabSynopsis { set; get; } }
局部页代码文件名
_LabListSelect.cshtml
@using Web.BLL; @model Web.Areas.LabArea.Models.LabListVm <div class="mrcTableContent" id="mrcTableContent"> <div class="mrcTableContentbody"> <table class="table table-border table-bordered table-bg table-hover table-width"> <thead> <tr class="text-c"> <th width="80">实验室编号</th> <th>实验室名称</th> <th width="80">实验室地址</th> <th width="80">实验室状态</th> <th width="75">实验室使用次数</th> <th width="120">实验室简介</th> </tr> </thead> <tbody> @foreach (var item in Model.LabListTables) { <tr class="text-c"> <td> @Html.DisplayFor(modelItem => item.LabId) </td> <td> @Html.DisplayFor(modelItem => item.LabName) </td> <td> @Html.DisplayFor(modelItem => item.LabAddress) </td> <td> @Html.DisplayFor(modelItem => item.LabStatus) </td> <td> @Html.DisplayFor(modelItem => item.LabUseNum) </td> <td> @Html.DisplayFor(modelItem => item.LabSynopsis) </td> </tr> } </tbody> </table> </div> <div class="pagehtml"> <div class="pages"> <div class="pagingtext"> 每页 @Model.PagingInfo.ItemsPerPage 条记录,共 @Model.PagingInfo.TotalPages 页,当前第 @Model.PagingInfo.CurrentPage 页 </div> @Html.PageLinksHtmlString(Model.PagingInfo, d => Url.Action("Index", new { page = d })) </div> </div> </div>
局部页需要后台代码
public ActionResult GetrListLabResult(string name,int page=1) { LabListVm labs=new LabListVm { LabListTables = db.LabTables.Where(lb => lb.LabName == name).OrderBy(d => d.LabId).Skip((page - 1) * LabListVm.PageSize).Take(LabListVm.PageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = LabListVm.PageSize, TotalItems = db.LabTables.Count() } }; return PartialView("_LabListSelect",labs); }
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:.net Mvc框架原理
下一篇:管线事件
- asp.net源程序编译为dll文件并调用的实现过程 2020-03-29
- Asp.net MVC SignalR来做实时Web聊天实例代码 2020-03-29
- ASP.NET MVC中jQuery与angularjs混合应用传参并绑定数据 2020-03-29
- Asp.Net中WebForm的生命周期 2020-03-29
- ASP.NET使用Ajax返回Json对象的方法 2020-03-23
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash