Well, I need to create two questionnaires that are almost equals. The difference are that one have a question more than the other. So I created a class with only the ID (to persistence) to be the base class for both:
public class BaseQuizzClass{
public int ID {get;set;}
}
And then I created the classes, with almost the same names for the variables ( I thought that it could help using razor):
public class Quizz1 : BaseQuizzClass{
[Display(Name="QuestionHere")]
public string q1 {get;set;}
[Display(Name="QuestionHere")]
public string q2 {get;set;}
...
[Display(Name="QuestionHere")]
public string q9 {get;set;}
}
public class Quizz2 : BaseQuizzClass{
[Display(Name="QuestionHere")]
public string q1 {get;set;}
[Display(Name="QuestionHere")]
public string q2 {get;set;}
...
[Display(Name="QuestionHere")]
public string q9 {get;set;}
[Display(Name="QuestionHere")]
public string q10 {get;set;}
}
Then I created a View using the BaseQuizzClass as model, so I could pass an child class as parameter toit. But I don’t know how to access the childs class attributes.
OBS.: Each question has your own text, defined in the Display annotation.
There’s any way to do what I want? (I’m not pretty sure if I was clear)
I would probably switch the model up a bit:
Then create a view for the question, and instead of using the
[DisplayAttribute]using the “key/value” setup of the object.It just appears over-kill to have that much similarity, yet explicitly calling out each question in your “different” objects.