How do partialviews work in asp.net MVC when passing parameters back?
I have a page with a partialview on it which is a list of items. I have a button on it which shows the next 5 items.
This is done via ajax:-
using (Ajax.BeginForm("ShowUpdates", new AjaxOptions() { UpdateTargetId = "statusUpdateContainer", InsertionMode = InsertionMode.InsertAfter }))
{
<input type="submit" class="formbutton" value="Show More" style="width:100%;"/>
}
My partial view controller:
[HttpPost]
public ActionResult ShowUpdates(string page, string pagesize)
{
//get data code hidden here
return PartialView("_statusUpdates开发者_运维百科");
}
My question is that I need the 'page' variable to increment each time someone presses the form button which is contained within the partialview.
How do I keep track of that variable?
You need to keep state of the page variable, and one solution its to have it in the View that render the partial view, because the partial view has access to the set of data of the View (the dictionary and the Model) or you can send it as a parameter. <%: Html.Partial("_statusUpdates", PageOrPageData) %>
精彩评论