this question has answer here:
spent bit of time coming suitable title, i'm not sure if worded correctly. example, use person object, real application using more domain-specific:
public class person { public string name { get; set;} public string gender { get; set; } public string haircolor{ get; set; } }
basically, requirements allow user can input 0 - 10 person objects, map list<person> people
property in model.
the way thinking doing having block of inputs related single person:
<div> <label for="name">name</label> <input type="text" name="name"> </div> <div> <label for="gender">gender</label> <input type="radio" name="gender" value="male"> male <input type="radio" name="gender" value="female"> female </div> <div> <label for="haircolor">hair color</label> <input type="radio" name="haircolor" value="black"> black <input type="radio" name="haircolor" value="brown"> brown <input type="radio" name="haircolor" value="blonde"> blonde <input type="radio" name="haircolor" value="red"> red </div>
with "add another" button on bottom, append additional block of these inputs using jquery.
my question is, how generate name
attribute in html input tags bind list<person>
properly? <input type="text" name="people[0].name">
work?
split page 2 partial views. first partial view going return list of saved people. second partial view view add new person.
so 1 first load of page showing list button "add another". clicking "add another" call addperson partial view getter using jquery , replace div partial view called.
clicking save in addperson partial view post new person , refresh list.
Comments
Post a Comment