I've following JSON:
var QuestionTemplate = {
Name: "Simple addition",
MathML: "mathML goes here",
Expression: "a+b",
QType: "mcq",
Rules: {
a: {//a is variable from expression(a+b)
variableType: "Single Digit",
min: "1",
max: "6"
},
b: {//b is variable from expression(a+b)
variableType: "Two Digit",
min: "20",
max: "80"
}
}
};
In rules "a" and "b" are variables from expression "a+b". If expression is a+b+c, there will be three variables a,b and c.
Now I want to map above json to my model in MVC.
What I've tried so far:
Model:
public class QuestionTemplateModel
{
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string Id { get; set; }
public string Name { get; set; }
public string MathML { get; set; }
public string Expression { get; set; }
public string QType { get; set; }
public Rules Rules { get; set; }
}
public class Rules
{
public List<variable> variable { get; set; }
}
public class variable
{
public List<VariableDetails> VariableDetails { get; set; }
}
public class VariableDetails
{
public string variableType { get; set; }
public string min { get; set; }
public string max { get; set; }
}
But when I send my json to model Rules is null, where as Name, MathML, Expression, QType are mapped properly. How I need to structure my model. What mistake I am doing.