asp.net mvc - MVC5 Scaffolding Dropdowns Out the Box -
i want view, edit , create drop-down list of lookup relationships.
sometimes works, doesn't. it's mystery i'm hoping can solved here.
here's poco's lookup
public class color { public int id { get; set; } public string value {get;set;} } //red,white,blue public class size { public int id { get; set; } public string value { get; set; } } //s,m,l
and here main object i'd have color , size drop-downs scaffolding out of box.
public class product { public int id; public string name; public virtual color color; public virtual size size; }
this isn't working me. neither size or color showing when it's time view, edit or create product. see name field.
size , color lazy loaded default (virtual) need eagerly load them:
var products = context.products.include(p => p.color).include(p => p.size).tolist();
https://msdn.microsoft.com/en-us/data/jj574232.aspx
if issue drop downs, want compose viewmodel in controller has list items, send view , use dropdownlistfor(m => m.colorid, m.colors). may need add colorid , sizeid product model. here explanation: http://odetocode.com/blogs/scott/archive/2013/03/11/dropdownlistfor-with-asp-net-mvc.aspx
Comments
Post a Comment