asp.net mvc 5 - Populating Index view with view model. EF 6, MVC 5 -


i'm struggling , hope can (i've received lots of on topic) i'm working entity framework 6.1.3 , mvc5. in productscontroller index method looks so:

private applicationdbcontext db = new applicationdbcontext();  // get: /products/ public  actionresult index() {     var products = db.products.include(p => p.productimage);      ienumerable<displayproductsviewmodel> model = products.select(p => new displayproductsviewmodel()      {          id = p.productid,         name = p.productname,          image = p.productimage,          price = p.productprice.tostring() }).tolist();      return view(model); } 

my displayproductsviewmodel view model looks so:

namespace accessorizeforless.viewmodels {     public class displayproductsviewmodel     {         public int id { get; set; }         public string name { get; set; }         public string price { get; set; }         public productimage image { get; set; }     } } 

and index view looks so:

@model ienumerable<accessorizeforless.viewmodels.displayproductsviewmodel>  @{     viewbag.title = "index";     layout = "~/views/shared/_layout.cshtml"; }  <h2>index</h2>  <p>     @html.actionlink("create new", "create") </p> <table class="table">          <th></th>     </tr>  @foreach (var item in model) {     <tr>         <td>             @html.displayfor(modelitem => item.image)         </td>         <td>             @html.displayfor(modelitem => item.name)         </td>         <td>             @html.displayfor(modelitem => item.price)         </td>         <td>             @html.actionlink("edit", "edit", new { id=item.id }) |             @html.actionlink("details", "details", new { id=item.id }) |             @html.actionlink("delete", "delete", new { id=item.id })         </td>     </tr> }  </table> 

when view in browser empty page, nothing shows. no errors though that's step in right direction. first time working view models, , when debug model comes empty list.

i know set of eyes takes, can see i'm doing wrong?

edit

here's product ef model

namespace accessorizeforless.data {     using system;     using system.collections.generic;      public partial class product     {         public int productid { get; set; }         public int productimageid { get; set; }         public string productname { get; set; }         public nullable<decimal> productprice { get; set; }         public nullable<int> quantity { get; set; }         public string productdescription { get; set; }          public virtual productimage productimage { get; set; }     } } 

i'm going pull out view model , see if page populates


Comments