views:

41

answers:

2

So, I have a page that looks like the following: alt text

This is my basic messaging inbox. I have 2 pages right now, Inbox and Sent (there will eventually be others). These both share the same View, and just have 2 different actions to populate the appropriate data.

The elements on the right-hand side (the message list) is a partial view which has its data populated based on my two controller actions Inbox(int? page) and Sent(int? Page).

So, I have one view "MessageView" and one partial view "MessageList" shared between Inbox/Sent.

However, I now have to get those arrow buttons ("<" ">") working using Ajax. I know how to use jQueries ajax calls well enough, and I know how to render the result of the action call (which returns a partial view).

The problem comes from the fact that the javascript that makes these pagination ajax calls needs to know two things:

  • What the current page is (whether it be /messages/inbox or /messages/sent)
  • What the current page is (specified in the query string, ie /messages/inbox?page=2).

Without knowing which page I'm on (Inbox or Sent), it wont know which url to make the ajax call on. Should it make the postback to /messages/inbox or to /messages/sent?

If I wasn't making these messages load with Ajax it would be as simple as loading the appropriate url into the link tags for the "<" and the ">" buttons. But I can't, because part of my requirements states that it must load the messages below without visibly refreshing to a new page.

A: 

When the user clicks the Inbox or Sent buttons, you need to rewrite the URLs in your arrows so that they point to the right place.

Robert Harvey
When they click on the arrows, it isn't following a link. I'm making a jquery ajax call to load in the messages below. So, how would rewriting the urls help me?
KingNestor
Also, what if they travel to www.mysite.com/messages/sent. The javascript now needs to know that the sent page was loaded directly. Because a user didn't click "Sent" on menu.
KingNestor
Then you could just rewrite the onclick event for them instead. `$('#nextArrow').bind('click', {box:myBox, page:myPage}, function(e) { doMyAjaxCall(e.data.box, e.data.page); })`
Jacob
+1  A: 

In JavaScript you can check window.location.pathname to see the pathname section of the current’s page’s URL.

window.location.search gives you the query string.

Paul D. Waite