asp.net mvc - Rebinding a list of textboxes in ASP MVC2 VS2010 Beta2 after postback -


So .. I have a problem. I was sure that almost anyone tried MVC Despite this, I have failed to score a solution or think one for myself.

The problem is this: I have a list of text boxes which I would like to edit every one at a time, even though D also likes to add new items to my list, though the text post binding after the first postback Fails.

So I have made a small example to clarify this problem:

 using   & Lt; P & gt; & Lt;% = Html.TextBox ("list", s)%> & Lt; / P & gt; & Lt;%}% & gt; & Lt; P & gt; & Lt;% = Html.TextBox ("newstr")% & gt; & Lt; / P & gt; & Lt; P & gt; & Lt; Input type = "submit" value = "save" /> & Lt; / P & gt; & Lt; / Fieldset & gt; & Lt;%}% & gt;  

Controller code:

  [AcceptVerbs (edit.httpVerbs.Get)] Edit Public Functionality () {Return View (new list & lt; string & gt; ; () {"AA", "BB", "CC"}); } // Remove the empty string and add a new one [AcceptVerbs (HttpVerbs.Post)] Edit Public ActionSurst (list & lt; string & gt; list, string newstr) {list & lt; String & gt; Res = list.Where (S => String.IsNullOrWhiteSpace (s)). ToList (); If (string! Iasnell of whitespace (newstra)) res.Add (newstr); See Return (RES); }  

So, on the first GT, I come back 3 strings A, BB and CC, and get 3 text boxes in my text, as well as empty text boxes for new strings, Like:

  ABCcc is empty Now, if I clear the BB string and add "dd" to the empty text box, then I would say "A", "", "CC" And the return list of "DD" is found. I in the newstr gives a new list of "A", "CC", "DD", which is my checkbox Expects to see in S. Instead, I get:  
  aa aa dd (expected empty)  

So .. I have not got anything fundamental :) Why does it do my Ignore new data modals and use some of the old ones?

I think that any kind of viewer is used by asp.net, so how do I change it? I really want to advertise stateless webpage.

If you look at your html source you will see that it has nothing to do with the viewstate a post After filling the input, the structure searches the previously posted values ​​and fills your information based on it. That is why you will get "dd" in your final input why you get "aa" in the remaining inputs is that they have the same name. Your post will appear something like this:

list = "a", list = "", list = "cc"

So when you name the name "list" Will search and assume first, which matches. This will be "A" every time this is the reason why you get "AA" in all your inputs. You have multiple & lt; Input type = "text" / & gt; with unique names you will not be able to fix the problem with interesting input.

I'm not sure any & lt;% = Html.TextBox ()% & gt; Do not see data posted but you can always see it in a regular & lt; Input type = "text" can be changed to name = "newstr" /> and and it will work.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -