【发布时间】:2017-02-16 17:48:06
【问题描述】:
我不想在我的CustomerViewModel 上绑定Id 属性,所以我添加了一个[BindNever] 属性,但它不起作用。有什么解决办法?
我有以下几点:
CustomerController.cs
// PUT api/customers/5
[HttpPut("{id}")]
public async Task<IActionResult> Put([FromUri] int id, [FromBody]CustomerViewModel customer)
{
//Implementation
}
客户视图模型
public class CustomerViewModel
{
[BindNever]
public int Id { get; set; }
public string LastName { get; set; }
public string FirstName { get; set; }
public string Email { get; set; }
}
如果我输入以下 json 。 id 属性仍然被绑定
{
"id": 100,
"lastName": "Bruce",
"firstName": "Wayne",
"email": "bruce@gothamcity.com"
}
【问题讨论】:
标签: c# asp.net-core asp.net-core-mvc model-binding