[英]Bind in asp.net core does not work
另一个选择是创建一个单独的模型,仅包含所需的属性并绑定该模型。
public class MyModel
{
public int Iva {get;set;}
public string Path {get;set;};
// other properties
}
然后在控制器中
public Task Index()
{
var marca = _context.GetMarca();
//map marca to MyModel here
var model = new MyModel()
{
Iva = marca.Iva,
Path = marca.Path
// other properties
}
return Index(model);
}
public async Task<IActionResult> Create(MyModel model)
{
var entity = _context.GetEntityByID(model.Iva);
entity.Path = model.Path
//map other properties
await _context.SaveChanges();
}
我更喜欢绑定不同的模型,而不是绑定实体来查看。
只需在控制器函数中使用[frombody]属性,因为httppost值来自请求的主体部分。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.