tags:

views:

143

answers:

1

On a single view I will have three sets of paged data. Which means for each model I will have

  • The Objects
  • The Page Index
  • The Page Size

My initial thought was for example:

public class PagedModel<T> where T:class
{
    public IList<T> Objects { get; set; }
    public int ModelPageIndex { get; set; }
    public int ModelPageSize { get; set; }
}

Then having a model which is to be supplied to the action as for example:

public class TypesViewModel
{
    public PagedModel<ObjectA> Types1 { get; set; }
    public PagedModel<ObjectB> Typed2 { get; set; }
    public PagedModel<ObjectC> Types3 { get; set; }
}

So if I then for example have the Index view inherit from the type:

System.Web.Mvc.ViewPage<uk.co.andrewrea.forum.Web.Models.TypesViewModel>

Now my initial aciton method for the index is simply:

    public ActionResult Index()
    {
        var forDisplayPurposes = new TypesViewModel();
        return View(forDisplayPurposes);
    }

If I then want to page, it is here where I am struggling to decide which action to take. Lets say that I select the next page of the Types2 PageModel. What should the action look like for this in order to return the new view showing the second page of the Types2 PageModel

I was thinking possibly to duplicate the action but use it with POST

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Index(TypesViewModel model)
{
    return View(model);
}

Is this a good way to approach it. I understand there is always Session, but I was just wondering how such a thing is achieved currently out there. If any best methods have been mutually accepted and things.

So simply, one page with multiple paged models. How to persist the data for each using a wrapper model. Which way should you pass in the model and which way should you page the data, i.e. Form Post

Lastly, I have seen the routes take this into account i.e.

{controller}/{action}/{id}/{pageindex}/{pagesize}

but this only accounts for one model and I do not really wwant to repeat the pagesize and pageindex values for the number of models I have inside the wrapper model.

Thanks for your time!!

Andrew

A: 

IMHO if you would have not just collection of objects, but collection of some extended type, for instance, something like:

public class PagedModelElement<T> where T:class
{
    public byte Step { get; set; }
    public string Name { get; set; }
    public T Value { get; set; }
}

public class PagedModel<T> where T : class
{
    public IList<PagedModelElement<T>> Objects { get; set; }
}

ModelPageIndex is not needed, because you can easily return all the objects belonging to some page (you may use indexer) as well as ModelPageSize could be calculated by Count() function of all objects belonging to some page.

So you do not need to worry about passing these two parameters into URL, the only param you need is PageNo:

{controller}/{action}/{pageNo}
Account/ShowUsers/3
Andrey Tkach
Hi thanks for the comment. But what I mean is on one page you have 3 sets of data for example and each can be paged separately. So for instance Data Set 1 is on Page 1, Data Set 2 is on Page 5 and Data Set 3 is on Page 50! It is this scenario I am thinking about currently! I appreciate your time and feedback though! Andrew :-)
REA_ANDREW