Dynamically Constructing Lists on Client-side on ASP.Net MVC2
I need to create a list of dynamically generated entries on the client as the user can control how many entries he needs pressing a + symbol. Functionality in some sense is similar to the "Google Finance Stock Screener" add criteria.
In code I have a model that looks like this:
public class Model
{
public List<string> DynamicList { get; set; }
}
Now the first time the server may provide an empty list. The user from the web browser now can add using the + symbol editors for the dy开发者_如何学JAVAnamic list elements (in this particular case a TextBox).
Do you know of any way to implement this functionality without resorting to a request a new list to the server (that is through either a postback or an AJAX call) on each addition?
Thanks in advance.
PD: Question left open as community wiki for anyone to improve on the question itself.
The architecture you should be using implements AJAX calls. It should be something like that:
- Page rendered to user. List is empty. User presses + button
- If you need to store on your database, or session variable, each single addition, an ajax call is performed every time the + button is pressed. Data is sent to the server, which handles it as you see fit.
- If you don't need to store each single addition, you can have simple JS adding items on the page, and a save button at the end, which posts (through ajax or normal submit as you prefer) all the additions to the server.
精彩评论