SSA
SSA

Reputation: 5493

Go to next record from asp.net MVC details view

I am new to asp.net MVC, using MVC4 at the moment, learning by tutorials so be aware I am a newbie. :)

Question: I have an index page listing a sequence number and description, you click on sequence and you go to details, working fine no issue. In controller action I select details based on id. Now I want to implement navigation in details view, so that user can go to next sequence number(as in index page) without going back to index page. What approach should I follow? Is there any standard way? Tried searching examples but no luck there so far.

Upvotes: 0

Views: 2893

Answers (1)

ntziolis
ntziolis

Reputation: 10231

In your controller you add the code in the details method:

// id is the id that is passed into the details method
var nextID = db.Products.OrderBy(i => i.ID)
                     .SkipWhile(i => i.ID != id)
                     .Skip(1)
                     .Select(i => i.ID)

ViewBag.NextID = nextID;

Now you can use the assigned value within your details view (razor syntax):

<a href="/Products/Details/@ViewBag.NextID">Next</a>

Upvotes: 6

Related Questions