开发者

How do partialviews work in asp.net MVC when passing parameters back?

开发者 https://www.devze.com 2023-02-16 17:31 出处:网络
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.

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) %>

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号