gpt4 book ai didi

c# - 将通用参数传递给 MVC Action

转载 作者:太空宇宙 更新时间:2023-11-03 20:23:03 24 4
gpt4 key购买 nike

我正在构建一个 MVC Controller ,它将接受一个 JSON 对象,但我想让它接受的类型是通用的。我可以这样做吗?

public class RecognitionData<T> 
{
DateTime StartTime { get; set; }
DateTime EndTime { get; set; }
T Value { get; set; }
}

public class Address
{
string Line1 { get; set; }
string Line2 { get; set; }
string Locality { get; set; }
string Country { get; set; }
string Postcode { get; set; }
}

public class AddressController : Controller
{
public string Save(RecognitionData<Address> result)
{
...
}
}

当我尝试将数据作为 JSON 发布时,虽然我可以看到 Request["result"] 中的“result”字段是一个字符串,但“result”参数为空。

知道我做错了什么吗?

最佳答案

尝试公开模型中的属性。

关于c# - 将通用参数传递给 MVC Action,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12314219/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com