MVC中局部視圖的使用

來源:互聯網
上載者:User

標籤:des   cPage   分頁控制項   blog   http   io   ar   使用   sp   

載入部分視圖

$("#result").load("/home/message",function(){

//載入完之後隱藏進度條

});

 

 public ActionResult message(){

   return PartialView("視圖",實體);

}

 

分頁控制項的使用

頁面:

 < div   id = " CommentList " >
@ { Html . RenderAction ( " Index " ,   " Comment " ,   new   {   id   =   @ Model . ProductID ,   page   =   1   } ) ; }
< / div > 

 局部視圖

 @ using   Webdiyer . WebControls . Mvc ;     @ model   PagedList < Extshop . Models . T_Comment >     @ {             foreach   ( var   c   in Model ) { < div class = " row " > < div class = " title " > @ c . Title < / div > < b > @ c . Username < / b > & nbsp ; 發表於 @ ( c . CreateTime ) < br / > @ c . Description < / div > } } < br / > < div class = ‘ pagenav ‘ > @ Ajax . Pager ( Model , new PagerOptions { PageIndexParameterName = " page " } , new AjaxOptions { UpdateTargetId = " CommentList " } ) < / div > 
Ajax分頁的方法,這樣,就可以使用Ajax自動更新該部分。在AjaxOption中定義了UpdateTargetId參數為“CommentList”,意味著當Ajax載入資料後,會自動更新id為“CommentList”的html元素內的內容
或
 @Html.Pager(Model, new PagerOptions{    PageIndexParameterName = "id", ShowPageIndexBox = true, FirstPageText = "首頁", PrevPageText = "上一頁", NextPageText = "下一頁", LastPageText = "末頁", PageIndexBoxType = PageIndexBoxType.TextBox, PageIndexBoxWrapperFormatString = "請輸入頁數{0}", GoButtonText = "轉到"})

後台:

 建立一個名稱為“CommentController”的控制器,並修改index作業碼如下:                     public   ActionResult   Index ( int   id , int ?   page )                     {                             ViewData [ " ProdcutID " ] = id ; PagedList < T_Comment > q = dc . T_Comment . Where ( m = > m . ProductID = = id ) . OrderByDescending ( m = > m . CreateTime ) . ToPagedList ( page ? ? 1 , 2 ) ; return PartialView ( q ) ; } 代碼中第1個參數id表示的是產品的id,第2個參數是評論的當前頁。和產品列表一樣,使用mvcPager進行分頁。

 MvcPager.rar

 PagerTest.zip

MVC中局部視圖的使用

聯繫我們

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