[英]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.