views:

284

answers:

2

My application has 10 products that are listed on a products page. When a user clicks one of these products they get directed to the details page for that product.

I would like to implement a next/previous pager on the details page that takes you to the next or previous product without having to go back to the products page.

I am assuming I have to write strongly typed view data that returns both the Product object as well as identifiers (SKU in this case) for the next and the previous product based on the product selected.

public class ProductViewData
{
    public Product product
    {
        get;
        set;
    }

    public string NextSKU
    {
        get;
        set;
    }

    public string PreviousSKU
    {
        get;
        set;
    }
}

The question is, how do I get to the previous and next identifiers using LINQ in a efficient way?

Thanks

A: 

Thomas, there's no need to write a LINQ statement for this. There's an MVC-compatible control for this called JQGrid that will do the job. http://www.trirand.com/blog/

Austin
I should point out, however, that you WILL have to make your model data json-compatible in order for this to work--that is how the control knows how to iterate.
Austin
A: 

I suggest the .Skip() and .Take() Extensions to IEnumerable:

var out = customers.Skip((pageNumber - 1) * 3).Take(3).ToList<Customer>();

...then you can use out[1] to target the middle one. You might also want to cache customers. This form actually comes from another stackoverflow.com answer.

rasx
The problem is that I don't have a pagenumber since I am not doing paging. All I have is a SKU number and I have to query the database for that SKU to display details as well as get the SKU of the product before and after.
Thomas
I think we have a parallel-universe stalemate here: you win.
rasx