0

Say you have a page that provides a list of songs depending on some identifier you have specified, such as a category it belongs to. You may have your URL formatted like so:

http://mysite.com/songs/view/1

Now lets say you wanted to add paging, what is the best way to structure that URL and how does the action method work? I am assuming something like this is incorrect

http://mysite.com/songs/view/1/page/2

Thanks

2 Answers 2

1

I think that that would be fine, or some variations:

  • /songs/view/1/page2
  • /songs/view/1?page=2
  • /songs/view/1/2

or you could keep it in a cookie or something, and just not have to deal with it in the URL at all.

Sign up to request clarification or add additional context in comments.

Comments

0

If you have your url as http://mysite.com/songs/view/1/page/2 you would always require that the word page to be in the url.

Now if it was http://mysite.com/songs/view/1/2 where 2 being the page number and nullable you could still call http://mysite.com/songs/view/1 which would be your first page.

The routing engine is smart enough to append the page number when it has a value.

public ActionResult View(int id, int? page)
{

}

MapRoute("songs.view", "songs/view/{id}/{page}", new { controller = "songs", action = "view", id = "", page = "1" });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.