I am working in ASP.NET 3.5 MVC application. We have a functionality where we search for say "Customer search results", using some parameters.
If the user enter some search parameters like say, Date of birth/SSN/address, and hits search, the search results are displayed in a grid below. One of the records in the results can be clicked and it navigates to the customer information page. And from that page you can click on "Return to Search results" to come back to the search results page again, which can potentially show up the search parameters and the results of the last search.
We use sql server session state. And I am using the viewmodel and model binder to store the search parameters and results. So when the user comes from Customer information page back to search results page I am using the data stored in my model binder to bind the search results back.
However say the user is in customer information page and by the time the session expires, and when user tries to return back to search results page, the search parameters and search results are lost.
I should be able to pull the search parameters from SOMEWHERE where it can be restored(the store should not be a SESSION) when the information is lost. What I was trying is to store the parameters in the SQL table and pull it back when the data in my session is lost.
I don't necessarily worry about the search results as I may need to call a service to pull the results, but only care about the way to retrieve the search parameters when its lost due to session expiry.
May I know if there is any other way to do this apart from storing the search parameters in a table?
SARAVAN - you can use localstorage (if using javascript). this is implemented in quite a few libraries out there and is even used as part of the jquery .data() method. i'm using mvc2 and make a lot of use of this mechanism - it works!!
see:
http://dev.w3.org/html5/webstorage/#the-localstorage-attribute
or
http://en.wikipedia.org/wiki/Web_Storage
or
http://msdn.microsoft.com/en-us/library/cc197062%28VS.85%29.aspx
jim
[edit] some localstorage jquery links:
http://plugins.jquery.com/project/DOMCached
http://plugins.jquery.com/project/jStorage
Related
I have a search control that breaks results into multiple pages. Currently it operates by executing the query then storing the results in a session variable. When a second, third, x page of results is requested it pulls the data from session to display the required elements.
However once the page is navigated away from the session data remains unnecessarily. It seems like I'd want to remove it once I no longer need it. On the other hand, if the user navigates back to the search results, keeping it in session data means I don't need to re-run the query... though it seems possibly dangerous.
I'm wondering if there's a standard practice that's worth following in this scenario that someone could link me to or suggest to improve the design that's in place.
Thanks.
I am using the Knockout: Contacts editor example http://knockoutjs.com/examples/contactsEditor.html as the template to start my MVVM project.
At the top of my page I have a set of cascading combo boxes that allow the user to drill down to a master record. When the user clicks the refresh button, an AJAX call finds the corresponding detail records from the server matching the user's search criteria. I load them into my viewmodel using ko.mapping.
My viewmodel is not as nested as the example, so I don't have anything at the "phone number" level. I do still want to add and delete records at the "first name / last name" level.
I am familiar with making AJAX calls to the server. I've looked at countless examples, but I still haven't found a good example of what the server side code should look like. Could someone point me toward an example that uses a list of objects like the example I am working with and what the VB.Net code looks like on the controller for adding, updating, and deleting database records using entity framework?
I have a very simple ASP.NET MVC site which displays images from the database. The user fills out some search parameters and a View returns a list of images from the database which match the search criteria.
I'm now adding Pagination, where depending on the page number I skip a certain number of images retrieved from the database. I've got this working for the first page. My search parameters are lost when I click on the second page of results as I have no mechanism in place to store the search parameters between Views at the moment.
What's the best approach to take. I could have lots of search parameters. Should I store them all in the Session or in hidden fields? That feels like a hack. Should I have a seperate ViewModel to hold the search params and store that in the Session?
What's the typical approach to take?
You would typically store cross-pagination data in hidden fields. For scalability, sessions should be limited to session-wide related data. If putting the data in hidden fields opens a vulnerability, you can consider serializing a view model and encrypting it as one hidden field. Putting it in the URL is another option, although you are limited to the amount of content you can put there.
I would put them all in the querystring of your "Next" and "Previous" links. This would allow visitors to bookmark the full URL and return to the same page with the same sort and filter settings.
My application (Asp.Net MVC) has great interaction with the user interface (jQuery/js). For example, setting various searches charts, moving the gadgets on the screen and more .. I of course want to keep all data for each user. So that data will be available from any page in the Dumaine and the user will accepts his preferences.
Now I keep all data in a cookie because it did not seem logical asynchronous access to the server each time the user changes something and thet happens a lot.When the user logout from the application I save the cookie to the database.
The Q is how to save the settings back to the db - from the client to the server.
because the are a lot of interactin that I want to record.
example scanrios: closing widget,moving widget,resizing menues, ordering columens..
I want to record that actions. if I will fire ajax saving rutine for each action
ןt will be too cumbersome. Maybe I have no choice..
Maybe I should run an asynchronous saving all of a certain interval seconds.
The problem is the cookie becomes very large. The thought that this huge cookie is attached to each server request makes me feel that my attitude is wrong.
Another problem cookies have size limit. It varies from your browser but I definitely have been close to the border - my cookie easily become 4kb
Is there another solution?
Without knowing your code, have you considered storing the users preferences in a/your database. A UserPreference table with columns for various settings is a possibility.
You could update it via AJAX/JSON if you had a 'Save Preferences' option, or just update it on postback.
EDIT 1: After thinking about it, I think having an explicit 'save preferences' button would be beneficial and practical.
Somewhere on your page, where the use edits the things that generate the cookie, put an button called save, then hook up a jQuery click handler. On click, build a CSV string or another method of storing the preferences for posting back to the server, then use $.post to send it back to an action method in a controller.
Once there, store it in the database somehow (up to you exactly how), then return a JSON array with a success attribute, to denote whether the preference storing was successful.
When the page is loading, get the preferences out of the database and perform you manipulation.
Another solution would be to store the user preferences into the session and write some server side logic (like action filter) that would write those preferences as JSON encoded string on each page (in a script tag towards the end of the markup) making them available to client scripts.
using asp.net mvc, I'm initializing a list in the server code, and allowing the end-user to add to the list on the form (using JQuery to add entries). I know how to obtain a list's selected items on a post back, but I don't need to do that here. I want the complete contents of the list accessible in the server code after a post back.
Is a posted list just not going to give me the full content? Should I use Ajax to send each item to the server as each items gets added to the list?
thanks
There are a couple of ways that I can think of doing this.
make an ajax call each time an item is added - as you suggested
when an item is added to the list, you also add a hidden field to the form that will be submitted. Then on post back (although that terminology is very Web Forms-y), in your action method, you'll have access to the contents of the list. If you name things correctly you should be able to model bind to a List.
The latter would be my preference, it depends on your particular situation though.
Some things to keep in mind:
Bandwidth from the user to the web server is very small compared to bandwidth from a database to the web server
The database most likely cached whatever query you just ran to populate that list
It sounds like you're asking for the entire list to be included with the postback data, and that means having the browser upload that data for the user.
With all that in mind, it should be obvious that you're better off rebuilding your base list from the database.