I have following model class:
public class TrackModel
{
public string Field;
public ExampleClass Value;
}
public class ExampleClass
{
public string Type { get; set; }
}
public class TextClass : ExampleClass
{
public string TextField { get; set; }
public string ValueFiled { get; set; }
}
I need to receive instance of TextClass with his fileds. I try do do following:
public class DefaultController : ApiController
{
public string Post(TrackModel model)
{
TextClass textTerm = model.Value as TextClass;
return "something";
}
}
But "textTerm" every time is null.
JSON request:
{
"Field":"string",
"Value": {
"Type":"type",
"TextField":"textfield",
"ValueField": "valuefield"
}
}
I need exactly this class hierarchy. How can I map it correctly? Maybe JsonConverter? C someone in this example show how it's work? Or I can hear any solutions to this problem.