asp.net - Does not contain a public definition for 'GetEnumerator' in MVC -
i trying solve 2 days.
the error is
compiler error message: cs1579: foreach statement cannot operate on variables of type 'mvc_ado.net_crud.models.businessobject.contactperson' because 'mvc_ado.net_crud.models.businessobject.contactperson' not contain public definition 'getenumerator'
my controller
public actionresult list() { var model = contactpersonmanager.getlist(); return view(model); } in model
public static contactpersonlist getlist() { contactpersonlist templist = null; using (var myconnection = new sqlconnection(appconfiguration.connectionstring)) { var mycommand = new sqlcommand("uspcontactpersonselectlist", myconnection) { commandtype = commandtype.storedprocedure }; myconnection.open(); using (var myreader = mycommand.executereader()) { if (myreader.hasrows) { templist = new contactpersonlist(); while (myreader.read()) { templist.add(filldatarecord(myreader)); } } myreader.close(); } } return templist; } my view
@foreach (var person in model) { <ul> <li> @person.id; </li> </ul> } am missing or doing thing's wrong?
instead of
@model mvc_ado.net_crud.models.businessobject.contactperson have
@model ienumerable<mvc_ado.net_crud.models.businessobject.contactperson> in view.
this assumes contactpersonlist implements ienumerable<contactperson>. if not, try
@model contactpersonlist however not clear custom type, contactpersonlist, is.
Comments
Post a Comment