How to transfer to another page in MVC

I have inherited a system written in MVC (5?). It has a page that contains a dropdown of options (by user, by page) and an input box. The "Find" button is an HTML button which is attached to a JQuery click event function. The function makes a $.get call to a partial view and loads it into a div on the current page.

The results also contain links that allow switching between the available options (user, page), so if it is a list of pages by user - there will be a link to see users by page.

That all works as expected (whether or not it is the best / correct way of doing it). Although it does have the issue that users cannot use the back button.

The problem I have is, for various reasons, the page needs to be split into two - pages by user and users by page. However, I still need to provide the ability to switch between the two different views. Now that they are different pages / urls the method of switching (getting data via Ajax and injecting it into a div) doesn't work.

So, the question is, how can I click on a link (?) on one page and transfer to the other page and display the results, using the key value passed (either user Id or page Id)?
Gordon SaxbySenior Web DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I'm not sure what you're asking.
How to put an url in a link?
How to retrieve the id from the request in the controller?
Gordon SaxbySenior Web DeveloperAuthor Commented:
Each page ("pages by user" and "users by page") have an input text box and a button. Clicking the button activates a JS script which uses Ajax to get the data / partial view which is then put into the target DIV. Having searched Google a lot, this seems to be the standard way of doing it.

So, the "pages by user" page will take a user name and list the pages they have access (edit rights) to. Against each page listed, there is a link that will take you to the "users by page" page and display the users that have access to the selected page. There is a similar link on the "users by page" page.

My question is - how do I make that link work? Because each page gets the information using a partial view, how do I transfer to a page, passing the key value (user name or page id) and make the page load its data automatically?

The closest I have got so far is either the data loads into the existing page (i.e. the "pages by user" data loads onto the "users by page" page), or the correct page loads but the data doesn't. Can I link the two pages as they are, or does the whole solution need changing?
You can use your code to load the data in the div. I guess that code needs an id somewhere. You probably just need to have that id injected into the javascript code and have that code run when the page loads.

Here's more or less what you could do to make it work:

Put an id in the links:
<a href="/controller/action?id=someid">

Open in new window

Get that id in the action method and put it in the ViewBag :
ActionResult action(String id)
            ViewBag.Id = id;
            return View();

Open in new window

Put that id in the javascript at the right place in the javascript code:
$.get("getthepartialviewdata?id=@ViewBag.Id", .....)

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.