ASP.NET MVC Dynamic List Binding -


i have typed mvc page wont bind unorder list list of objects. in mvc view might like

<% foreach (var item in model.whatyoudol) { %> <li><%: html.encode(item.text) %><input type="hidden" name="whatyoudol[0].reference" /></li> <% } %> 

my view model might like

public class viewmodelquotewhatyoudoinmotortrade     {         public list<whatyoudo> whatyoudol { get; set; }     } 

and list contains object

public struct whatyoudo     {          public decimal percent { get; set; }         public string reference { get; set; }         public string text { get; set; }     } 

this binds ok providing use whatyoudol[0].reference index ([0]) when loading can set index. problem want add , remove list on client side. might have js adds , list item , removes current. means have somehow manage indexes in name , keep them in order , non duplicate on client side. know if there way around using index in name.

thanks in advance.

there is, probably, mistake:

<% foreach (var item in model.whatyoudol) { %> <li><%: html.encode(item.text) %><input type="hidden" name="whatyoudol[0].reference" /></li> <% } %> 

maybe should be:

<% foreach (var item in model.whatyoudol) { %> <li><%: item.text %><input type="hidden" name="<%: item.reference %>" /></li> <% } %> 

you don't need encode long use <: proof


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -