[英]Add Strongly Typed List to Database
I am trying to add some entries to a database in a controllers HTTP post event. 我试图在控制器HTTP post事件中向数据库添加一些条目。 However I am getting the following error: 但是我收到以下错误:
The entity type 'List' was not found. 找不到实体类型“列表”。 Ensure that the entity type has been added to the 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 the table to the DbContext: 我已将表添加到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 to write the following code. 您需要编写以下代码。
_context.WBLoading.add(wBLoading);
await _context.SaveChangesAsync();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.