Install the Change JS package first
Home Page Code home page 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 "&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;})) { <div class= "Mrctablenav" > <input type= "text" name= "name" id= " placeholder=" Lab name " class=" Mrctablenav-input "> <button Name= "" id= "Btselect" class= "btn btn-success" type= "Submit" ><i class= " Hui-iconfont ">& #xe665;</i> Search Information </button> </div> } <div id= "Load_ajax" style= " Display: none "> Loading ......... </div> <div class= "Mrctablecontent" id= "mrcTableContent" > </div></div> background code on the main 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;}}
Local 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&NBSP;TABLE-BORDER&NBSP;TABLE-BORDERED&NBSP;TABLE-BG table-hover table-width "> <thead> <tr class= "Text-c" > <th width= > Lab Number </th> <th > Lab name </th>   <th width= > Lab Address </th> <th width= > Lab Status </th> <th width= > Lab Usage </th> <th width= > Lab Introduction </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" > per page @ model.paginginfo.itemsperpage records, total @Model .paginginfo.totalpages page, current section @ model.paginginfo.currentpage page </div> @Html. pagelinkshtmlstring ( Model.paginginfo, d => url.action ("Index", new { page = d })) </div> </div> </div>
Background code required for partial page
Public actionresult getrlistlabresult (string name,int page=1) { LabListVm labs=new LabListVm { lablisttables = db. Labtables.where (lb => lb. Labname == name). (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);}
ASP. MVC5 Local Refresh Ajax