簡體   English   中英

將通用參數傳遞給MVC Action

[英]Passing generic parameters into MVC Action

我正在構建一個MVC控制器,它將接受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”參數為空。

有什么想法我做錯了嗎?

嘗試將模型中的屬性公開。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM