c# - Using a class in a Foreach (MVC) -


i have tad of problem! in mvc giving me "system.nullreferenceexception: object reference not set instance of object." problem whenever tries run mvc.

basically, code in controller:

 public partialviewresult viewallfaults() {      list<adminlogentries> faults = new faultservice.faultserviceclient().getalloffaultdetails().tolist();                  viewbag.listoffaults = faults;      return partialview("_viewallfaults", faults); } 

this code in view:

@foreach (common.views.adminlogentries item in viewbag.listoffaults) { <tr>     <td>         @item.faultid     </td> {...} 

and class:

namespace common.views { public class adminlogentries {     public string faultid { get; set; }     public string description { get; set; }     public int productid { get; set; }     public string username { get; set; }     public datetime logdate { get; set; }     public int orderid { get; set; }     public string status { get; set; }  } } 

i read bit ienumerable couldn't implement or understand it. sort of help!

**update:**

so found out wasn't passing through controller method! must addressing partial in wrong way. wrote in main view:

 @html.partial("~/views/admin/_viewallfaults.cshtml"); 

that stopping accessing controller think..

try changing code to:

@foreach (common.views.adminlogentries item in model) 

as you're passing faults view view model in second parameter:

return partialview("_viewallfaults", faults); 

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -