c# - Method called by Web UI doesn't returns results -
i'm confused, have method:
public ienumerable<professionalmodel> getallprofessionals() { return context.professionalcontext .include(x => x.useraccountmodel) .include(x => x.useraddressmodel).tolist(); }
if call using console ui return 1 record (it works), if call using mvc application returns no 1 record!
console ui:
professionalcontext pcontext = new professionalcontext(); var list = pcontext.getallprofessionals(); foreach (var in list) { console.writeline(i.name); } console.readkey();
mvc web ui:
public class professionalcontroller : controller { public professionalcontext professionalcontext { get; set; } public actionresult index() { professionalcontext = new professionalcontext(); var professionals = professionalcontext.getallprofessionals(); if (professionals == null) { return httpnotfound(); } return view(professionals); } }
and problem not @ view, because i've debugged , var professionals
have no records.
any idea?
edit
my context:
public class tccdatabase : dbcontext { public dbset<useraccountmodel> useraccountcontext { get; set; } public dbset<professionalmodel> professionalcontext { get; set; } public dbset<useraddressmodel> useraddresscontext { get; set; } }
note return type
ienumerable<professionalmodel>
which means debugger may not display elements in list till ask evaluate.
double check there no records in professionals variable follows:
public actionresult index() { professionalcontext = new professionalcontext(); var professionals = professionalcontext.getallprofessionals(); debug.assert(professionals != null && professionals.any()); if (professionals == null) { return httpnotfound(); } return view(professionals); }
and if want see results instantly in debugger etc. this:
public list<professionalmodel> getallprofessionals() { //body }
Comments
Post a Comment