问题描述
问题:
以下使用 ModelMetadataType
的代码无法正常工作。
我尝试使用 MetadataType
,仍然没有给出预期的输出。
预期输出:
{ "myid": 0 }
当前输出:
{ "id": 0 }
代码:
using System.ComponentModel.DataAnnotations;
using System.Text.Json.Serialization;
using Microsoft.AspNetCore.Mvc;
namespace webapi.models
{
public partial class MyClass
{
public int id { get; set; }
}
[ModelMetadataType(typeof(MyClassMeta))]
public partial class MyClass {}
public class MyClassMeta
{
[JsonPropertyName("myid")]
public int id { get; set; }
}
}
其他详情:
dotnet 版本:dotnet 5
项目类型:webapi
使用的 IDE:VSCode 和 dotnet CLI
Stack Overflow 中的其他相关问题;
- ASP.NET Core MetaDataType Attribute not working
- MetadataType don't work with partial class in ASP.NET MVC
在这种情况下,上述答案都没有帮助。以下是有关 Metadatatype
属性
MSDN Link to MetaDataType attribute
请帮忙!谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)