I'm using .Net 5 and I have a data model with a string type property. When I use it in controller and user send a number or other type of value, I hope it can be automatically convert to string type instead of throw an error, how should I do that?
Thank you.
The model is like this:
public class Product
{
public string ProductNo { get; set; }
public string ProductName { get; set; }
}
and the input could be
[
{
"productNo": 123456,
"productName": "abc"
},
{
"productNo": "S123",
"productName": "def"
}
]