更改模型中的显示名称以响应显示
Changing display name in Model to show in response
我正在寻找一种方法来更改模型中 属性 的显示名称,以便在响应主体中大摇大摆地反映出来。
我尝试对字段使用 DisplayName
属性,但它似乎不起作用。
[DisplayName("Fucntion ID")]
public string FunctionId { get; set; }
[DisplayName("Function Description")]
public string FunctionDEscription { get; set; }
还有其他方法可以实现吗?提前致谢。
如果您使用 asp.net 核心 3.x 和 asp.net 5,您可以使用 System.Text.Json
.
中的 [JsonPropertyName("Fucntion ID")]
如果您使用 asp.net 核心 2.x,您可以使用 Json.NET
.
中的 [JsonProperty("Fucntion ID")]
参考:
https://www.newtonsoft.com/json/help/html/JsonPropertyName.htm
我得到了答案-
使用 [JsonPropertyName("Fucntion ID")]
而不是 [DisplayName("Fucntion ID")]
我正在寻找一种方法来更改模型中 属性 的显示名称,以便在响应主体中大摇大摆地反映出来。
我尝试对字段使用 DisplayName
属性,但它似乎不起作用。
[DisplayName("Fucntion ID")]
public string FunctionId { get; set; }
[DisplayName("Function Description")]
public string FunctionDEscription { get; set; }
还有其他方法可以实现吗?提前致谢。
如果您使用 asp.net 核心 3.x 和 asp.net 5,您可以使用 System.Text.Json
.
[JsonPropertyName("Fucntion ID")]
如果您使用 asp.net 核心 2.x,您可以使用 Json.NET
.
[JsonProperty("Fucntion ID")]
参考:
https://www.newtonsoft.com/json/help/html/JsonPropertyName.htm
我得到了答案-
使用 [JsonPropertyName("Fucntion ID")]
而不是 [DisplayName("Fucntion ID")]