Easyui+EF+MVC+WCF實現分頁

來源:互聯網
上載者:User

標籤:分頁   datagrid   wcf   mvc   json   

        高校平台中,後台使用EF架構,前端使用MVC結合Easyui,前端和背景連結採用WCF傳遞資料,現在來說說是如何?分頁的。

頁面:mvc+Easyui

        採用部分視圖的方式調用拼接表格的部分視圖,url放入頁面載入時調用的方法(controller+方法名),例如我的controller為Template,方法名為QueryTemplateData。

 <div id="ContentAreas">        @*先調用 對應的業務Controller中的表頭資料*@        @{Html.RenderAction("ShowTemplateProperties", "Template");}        @*載入 資料表格 datagrid 加參數——查詢業務資料的url  *@        @{Html.RenderAction("DataGrid", "ControlsPartial", new { url = "/Template/QueryTemplateData"});}    </div>
        效果如下:

   

Controller下的方法QueryTemplateData如下:

        pageSize指一頁顯示多少資料,pageIndex指第幾頁,out total,傳地址,返回當前表格中所有資料條目數。

 #region 查詢範本主表資料——頁面首次載入  朱丹 2014年12月21日16:26:48        /// <summary>        /// 查詢範本主表資料——頁面首次載入        /// </summary>        /// <returns>string</returns>        public ActionResult QueryTemplateData()        {            //pageSize頁大小            int pageSize = int.Parse(Request.QueryString["rows"].ToString().Trim());            //pageIndex第幾頁            int pageIndex = int.Parse(Request.QueryString["page"].ToString().Trim());            int total = 0;            List<ExamTemplateMainEntity> listData = new List<ExamTemplateMainEntity>();            ExamTemplateMainEntity enTemplate = new ExamTemplateMainEntity();            listData = userService.QueryTemplateMain(pageSize, pageIndex, out total);            var data = new            {                total,                rows = listData            };            return Json(data, JsonRequestBehavior.AllowGet);        }        #endregion
         值得注意的要為
         var data = new            {                total,                rows = listData            };            return Json(data, JsonRequestBehavior.AllowGet);
        此段代碼是調用vs中的Json方法,將資料轉換成如何Easyui表格分頁的Json串,Easyui分頁的Json串為:{"total":xx,"rows":[{...},{...}]}  total為總數  rows為資料數組。

         WCF和後台EF架構中的邏輯就不用我說了,只是將controller中的pageSize、pageIndex、out Total參數傳後後台,擷取資料庫中的資料返回到Controller就可以了,這樣就實現了分頁。效果如下:

   

總結:

        其實Easyui和MVC不難,再難,也要迎難而上,有困難了才是自己進步的時候!



Easyui+EF+MVC+WCF實現分頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.