It's mvc project. I have a html table on first page to list search result, two filters on the page top, one is a textbox, the other is a dropdown. In the table, there is a column called view. It's a link. From the link you will go to detail page. When you come back to the first page, the textbox and dropdown will loss the value that user inputted before. I would like they can keep user's input. For webform, it's easy. I can put them to session or viewstate. But in mvc, where should I stored the value and when come back can load those value? session or tempdata? Thanks
Asked
Active
Viewed 531 times
0
-
What's wrong with using a database? – Jamie Rees Jul 30 '15 at 13:40
-
1Perhaps instead of redirecting to another view that displays the filtered results based on the dropdown/txtbox, your could consider using ajax to call a controller that returns a partial view update the current page (and get better performance as well) – Jul 30 '15 at 13:41
-
[Here is a post](http://stackoverflow.com/questions/10756140/asp-net-mvc-and-state-how-to-keep-state-between-requests) related to this question. – zed Jul 30 '15 at 13:41
-
**Thank you all for your input**. @Stephen, could you please just provide me with a sample? – Mike Long Jul 30 '15 at 13:57
1 Answers
0
You can store your all selections and data in session. But for more speed you can make your search with ajax call as Stephen mentioned.
Try using jquery.get() method to load data with ajax call. This method sends a request to the page with/without data and reads the response. Response is the rendered html. You can find more information here https://api.jquery.com/jquery.get/
Assume that you have a PartialView action on your controller that accepts 2 parameters.
public PartialViewResult Search(string txt, string dropdown)
{
// do your search
return PartialView(YourModel);
}
And in your javascript code do the following
$.get('/Home/Search',{txt:'yourTextboxValue',dropdown:'YourDropdownValue'},function(data){
// data is the html response that generated in partial view
$('#yourSearchContentDiv').html(data);
});

Ugur Altay
- 81
- 3