Asp.net MVC5 partial refresh Ajax, mvc5ajax

Source: Internet
Author: User

Asp.net MVC5 partial refresh Ajax, mvc5ajax

Install and modify the js package first

Code homepage file code 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 = "lab name" class = "mrcTableNav-input"> <button name = "" id = "btSelect" class = "btn-success" type = "submit"> <I class = "Hui-iconfont" >&# xe665; </I> search for information </button> </div>} <div id = "load_ajax" style = "display: none "> loading ......... </div> <div class = "mrcTableContent" id = "mrcTableContent"> </div> background code on the home page
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 );}
Classes used in the background
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 ;}}
Partial Page code file name
_LabListSelect.cshtml
@ Using Web. BLL; @ model Web. areas. labArea. models. labListVm <div class = "mrcTableContent" id = "mrcTableContent"> <div class = "mrcTableContentbody"> <table class = "table-border table-bordered table-bg table-hover table-width "> <thead> <tr class =" text-c "> <th width =" 80 "> Lab No. </th> <th> lab name </th> <th width = "80"> lab address </th> <th width = "80"> lab status </th> <th width = "75"> lab usage </th> <th width = "120"> laboratory overview </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"> every page @ Model. pagingInfo. itemsPerPage records, total @ Model. pagingInfo. totalPages, the current @ Model. pagingInfo. currentPage </div> @ Html. pageLinksHtmlString (Model. pagingInfo, d => Url. action ("Index", new {page = d}) </div>
Background code is required for partial pages
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);}



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.