asp.net mvc 4 - View not binding correcty with the model -
i can figure out why it's not binding. have form listbox in partial view reload everytime click on checkbox fill listbox.
the code of modelview form :
<div class="row-fluid"> <div class="span3"> <label>fonction(s):</label> </div> <div class="span9" id="listefonction"> @html.partial("listerfonction", model) </div> </div> <div class="row-fluid"> <div class="span5 offset3"> <div class="fonctions_container"> @foreach (extranetclient.models.classes.fonctioncontact fonction in viewbag.fonctions) { string coche = ""; if ((@model.listefonctions).any(c => c.idfonction == fonction.idfonction)) { coche = "checked"; } <input type="checkbox" @coche class="checkbox" value="@fonction.idfonction" />@fonction.libellefonction <br /> } </div> </div> </div>
so can see, render partial view after "email" textbox. code :
@html.labelfor(contact => contact.selectedfonctionids, "listefonctions") @html.listboxfor(contact => contact.selectedfonctionids, new multiselectlist(model.listefonctions, "idfonction", "libellefonction"), new { disabled = "disabled")
the model associated view looks that:
private list<int> _selectedfonctionids; public list<int> selectedfonctionids { { return _selectedfonctionids ?? new list<int>(); } set { _selectedfonctionids = value; } } public list<fonctioncontact> listefonctions = new list<fonctioncontact>(); public multiselectlist listefonctionsselectlist { { return new multiselectlist( listefonctions, "idfonction", // datavaluefield "libellefonction" // datatextfield ); } } public contact() { } public contact( list<fonctioncontact> listefonctions, list<int> selectedfonctionids) { this.listefonctions = listefonctions; this.selectedfonctionids = selectedfonctionids; } public contact(int idcontact, string nom, string prenom, string email, string telephonefixe, string telephoneport) { this.idcontact = idcontact; this.nom = nom; this.prenom = prenom; this.email = email; this.telephonefixe = telephonefixe; this.telephoneport = telephoneport; } public contact(int idcontact, string nom, string prenom, list<int> selectedfonctionids, list<fonctioncontact> listefonctions, string email, string telephonefixe, string telephoneport) { this.idcontact = idcontact; this.nom = nom; this.prenom = prenom; this.selectedfonctionids = selectedfonctionids; this.listefonctions = listefonctions; this.email = email; this.telephonefixe = telephonefixe; this.telephoneport = telephoneport; }
but listbox of partial view not binding model. other informations not these in listbox. has idea ?
why forcing listbox's id here:
@html.listboxfor(contact => contact.selectedfonctionids, new multiselectlist(model.listefonctions, "idfonction", "libellefonction"), new { disabled = "disabled", **id="idfonctions"** })
listboxfor helper supposed generate listbox's id you, , id should same attribute should bind with. shouldn't selectedfonctionids?
was binding working before started using partialview? because previous question, see had:
@html.listboxfor(contact => contact.selectedfonctionids, model.listefonctionsselectlist, new { disabled = "disabled" })
in view (i.e., didn't set id attribute).
Comments
Post a Comment