Background
I have a page on my ASP.NET MVC web app for users to enter addresses into their address book. When the user enters in their address and clicks the submit button, the controller action that handles the form post then geocodes the address (retrieves latitude, longitude, and the full address in case the user forgot to enter in their state, zip code, etc.).
Now, it's entirely possible that the user didn't enter in enough information to get an exact match. In this event, the geocode service returns a list of best matches for the address specified. When this happens, I want to prompt the user with this list of best matches so that they can select which address they wish to use.
This is all working wonderfully. I store the list of best matches in the ViewData, and the page renders the items in the list as an unordered list if they are provided. Next to each of the addresses is a "Select" link which the user can use to select the address they wish to use. The "click" event of the "Select" link is hooked up using jQuery to replace the text in the original address textbox with the address the user is selecting and then click the submit button via javascript.
The Problem
When the user selects an address, I want my controller action to check if the address is already in their address book. If it is, then I want to return an error message indicating that this address already exists. I also want to re-render the list of possible addresses for the user to select from (e.g. if the user originally saw a list of 3 addresses to pick from and they choose one that was already in their address book, the page should show an error message and the 3 addresses to pick from again). How can I re-render the list of best matches without making another call to the geocoding service in my controller action?
In other words, I have an unordered list that was generated by the last controller action that I want to display to the user again. The items in the list were rendered as text strings and therefore aren't posted to my controller action. The only way I have been able to solve this so far is to store the list of address matches in session. Am I missing something or is that the way I should be going about this?
With an ASP.NET web forms application, I could simply store the best matches in ViewState and it would be available to me on the postback from the user selecting the address. Is there a similar mechanism for ASP.NET MVC?