【发布时间】:2021-10-07 01:30:47
【问题描述】:
我有一个用于绑定 QueryString 的模型,它遵循 c# 的命名对话,但 QueryString 处于不同的命名对话中。如何为分配给 FromUrl 的模型属性提供自定义属性名称?
// Will NOT work
public class FormatDatabaseRequest
{
[JsonProperty("_type")]
public string Type { get; set; }
[JsonProperty(Name = "awef_flag")]
public string AwefFlag { get; set; }
}
// Controller.cs
[HttpPost]
public async Task<HttpResponseMessage> FormatDatabaseAsync([FromUri] FormatDatabaseRequest request) {}
// Sample URL (QueryString MUST be named _type and awef_flag)
// https://localhost:43521/myControllerName?_type=asdfa&awef_flag=asdf
【问题讨论】:
标签: c# asp.net asp.net-web-api