c# - Add Strongly Typed List to Database -
i trying add entries database in controllers http post event. getting following error:
the entity type 'list' not found. ensure entity type has been added model.
code:
[httppost] [validateantiforgerytoken] public async task<iactionresult> create([bind("id,name,weight)] list<wbloading> wbloading) { if (modelstate.isvalid) { _context.entry(wbloading).state = entitystate.modified; await _context.savechangesasync(); return redirecttoaction("index"); } return view(wbloading); }
i have added table dbcontext:
public dbset<models.wbloading> wbloading { get; set; }
model:
public class wbloading { public int id { get; set; } public string name { get; set; } public int weight { get; set; } }
you need write following code.
_context.wbloading.add(wbloading); await _context.savechangesasync();
Comments
Post a Comment