我正在尝试使用FromHeaderAttribute绑定模型属性,根据文档,该属性应该适用于参数和属性。
不幸的是,由于某种原因,我无法让它适用于 PUT/POST 请求模型中的属性:
public class TestModel
{
[FromBody]
public string Value { get; set; }
// The property I want to be bound from header
[FromHeader(Name = "Origin")]
public string Origin { get; set; }
}
[HttpPost]
public void Post(
TestModel value,
[FromHeader] string origin)
{
Console.WriteLine(value.Origin); // always empty
Console.WriteLine(value.Value); // OK
Console.WriteLine(origin); // OK
}
Run Code Online (Sandbox Code Playgroud)
Asp.Net Core 应用程序 v2.2.0