Get Formcollection in Page Navigation

Asked

Viewed 287 times

0

In an ASP.NET C# MVC4 system I have some screens where I show some data. These screens have Filters and navigation (maximum limit of 10 data per page). I would like to know how I can record Formcollection in some way so that it passes in pagination. An example of my control:

public ActionResult Orcamentos(int? page)
{

}

public ActionResult Orcamentos(int? page, FormCollection form)
{

}

Within these methods I already do everything right, working properly and showing in the View correctly. Now in the View that is the problem, in the navigation of the pages I can pass the Form so that it enters the method with Form.

In View, the Pagination part is like this:

@Html.PagedListPager(Model, (page) => Url.Action("Index", new { page = page, form = @ViewBag.filtro }), PagedListRenderOptions.Classic )

So where ta @Viewbag.filter I would have to find a way to pass the Formcollection (I pasted the Viewbag just by example, because it cannot store the form)

  • page usually comes from a GET. FormCollection usually comes from a POST. What is the purpose of this implementation?

  • When displays the data in the View, and it is paged, when I click on a page number there, for example 3, I send page=3 and also need to send the Form because I made a Filter. The pagination code would be this: (where I put Viewbag.Filter I would have to pass a Formcollection @Html.Pagedlistpager(Model, (page) => Url.Action("Index", new { page = page, form = @Viewbag.filter }), Pagedlistrenderoptions.Classic )

  • 1

    It’s wrong. If you want to set a filter, it has to be by GET also, and not using FormCollection. Either you use named parameters or you use FormCollection. The two of them together don’t make it. If I were you, I’d use one Viewmodel defining not only the filter, but the page in question.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.