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 :)

4

1 回答 1

0

为什么不使用更标准的技术,例如<form>在搜索页面中指向将执行搜索的控制器操作的标记:

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

然后您将拥有 Search 控制器操作:

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

我在表单上使用了 GET 方法,该方法允许用户为结果页面添加书签并稍后返回。

于 2012-04-05T06:19:29.930 回答