Passing and Storing objects between Pages

Go To StackoverFlow.com

0

I'd like some advice on this issue. Basically, I have 2 pages (for simplicity sake), and the second page is completely dependent on the first page.

So lets say the main page is a search page, and the second page is a view page.

The site works off XML requests, and the ultimate aim is to keep the XML requests to a minimum as each request is a little slow. I considered using Sessions, but I've had some problems in the past with sessions being mixed between users randomly which i only manage to curb by changing the recycle process in IIS to a very small time frame, so I'm wondering if there is any other way. I've tried TempData, but that expires after one request, so a page refresh on the view page doesn't seem possible. (or is it?)

Anyways, we have the Search page that has, say, 5 attributes that are required by the View page, but only 2 are needed to make the XML request on the view page.

e.g.

Search Page Contains:

  • ID,
  • Name,
  • City,
  • Email,
  • Height

View Page needs the following from the Search page to complete the xml request:

  • ID,
  • Name,
  • Email

View Page displays all the information from the search page, plus everything in the XML response.

The link i have in the search page only has the ID in the url, so name and email are required for the XML request on the second page some how. Not sure if it's possible without sessions?

What i've tried is:

Store the search results in TempData. That way, when someone clicks the 'View' link (<a href="/view/123456">View</a>), the View page loads the search results like so:

var viewPage = SearchResults.Where(w => w.ID == id).FirstOrDefault();

The ViewModel then renders the page by grabbing the Name and Email from viewPage, making an XML request, and displaying the response, along with other required details from viewPage.

It works as expected with tempdata. Data only persists on the first request, dies on a page refresh. Sessions is the alternative, but is there any other?

(sorry for the wall of text :)

2012-04-04 07:11
by jzm
Just had quick look at your question and I remembered a project I have worked on just like that. I sorted out the issue by encrypting the values (e-mail, name, etc.) with asymmetric encryption algorithm and putting it as QueryString value. Also, keep in mind that TempData is using sessions as well - tugberk 2012-04-04 07:46


0

Why not using more standard techniques like a <form> tag in the search page pointing to the controller action that will perform the search:

@using (Html.BeginForm("search", "somecontroller", FormMethod.Get))
{
    ... some input fields for your search criteria
    <button type="submit">Search</button>
}

and then you will have the Search controller action:

public ActionResult Search(SearchModel model)
{
    var results = ....
    return View(results);
}

I've used GET method on the form which allows the user to bookmark the results page and come back to it later.

2012-04-05 06:19
by Darin Dimitrov
Ads