The use of partial views in MVC

Source: Internet
Author: User

Loading partial views

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

Hide progress bar after loading

});

Public ActionResult message () {

Return Partialview ("View", entity);

}

The use of paging controls

Page:

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

Detail View

@UsingWebdiyer. WebControls.     MVC; @ Model Pagedlist < Extshop. Models. T_comment >@ {foreach (var cInchModel) {< divclass ="Row"> < divclass = " title " > @ C. Title </div > < b > @ c. Username </b > & nbsp; Posted at @ (c. Createtime) < br/> @ C. Description </div > }} < br/> < div class = ' pagenav ' > @ Ajax. Pager (Model, new Pageroptions {pageindexparametername = " page "}, new Ajaxoptions {Update Targetid = " commentlist "}) </div >
Ajax method of paging, so that you can use Ajax to automatically update this section. The Updatetargetid parameter is defined as "commentlist" in ajaxoption, meaning that when Ajax loads the data, the contents of the HTML element with the ID "commentlist" are automatically updated
Or
@Html. Pager (Model,Newpageroptions{Pageindexparametername ="Idtrue, Firstpagetext =  " home "  Prevpagetext = Span data-mce-= "" > " prev "  NextPageText =  " next "  Lastpagetext =  " last " , Pageindexboxtype =  Pageindexboxtype.textbox, pageindexboxwrapperformatstring =  "  Please enter the number of pages {0} " " go to  "})         

Background:

Create a new controller named "Commentcontroller" and modify the index operation code as follows: Public                        actionresult   int   int?    Page)                     {                             ""] =2return Partialview (q);} The 1th parameter ID in the code represents the Product ID, and the 2nd parameter is the current page of the comment. As with the product list, use Mvcpager for paging. 

Mvcpager.rar

Pagertest.zip

The use of partial views in MVC

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.