Asp.net MVC5 局部重新整理 Ajax

來源:互聯網
上載者:User

標籤:failed   狀態   derby   bre   over   nbsp   options   inf   option   

先安裝改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">&#xe665;</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);}



Asp.net MVC5 局部重新整理 Ajax

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.