asp.net - Html.ListBoxFor error problem asp.mvc 3 -


i have in code , getting error: exception details: system.argumentexception: value cannot null or empty. parameter name: name . doing wrong ? help

@model ienumerable<nhibernatefluentproject.patient>

@html.listboxfor(model => model, new selectlist(model,"id", "firstname"));

@html.listboxfor used strong typed viewmodel. bind property. first part take lambda expression single item default seleced listbox, second part take item collections dispaly listbox items. example: have following 2 classes.

public class hospitalviewmodel {     public string selectedpatient { get; set; }     public ienumerable<patient> allpatients { get; set; } } public class patient {     public int id { get; set; }     public string firstname { get; set; } } 

from view, should like

@model hospitalviewmodel  @html.listboxfor(model => model.selectedpatient, new selectlist(model.allpatients,"id", "firstname")); 

or if want bind patients listbox, use html.listbox instead

@model ienumerable<patient>  @html.listbox("listboxname", new selectlist(model,"id", "firstname")); 

Comments

Popular posts from this blog

Javascript line number mapping -

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -