3
I am creating a project of questions and answers, more to consolidate my knowledge and acquire others. But when developing it I arrived at a question that I am thinking about which of the options would be better to create a model and therefore a table clean and easy to understand.
What I have is the following question: Which of the options (among which I thought it would be good to do) is the best?
- I put in my question model an attribute called Opcoesresposta with all the options that the question brings (a, b, c, d, e) and another call Answer and put in it the correct answer to the question; or
- Put four attributes (Opcao1, Opcao2, Option 3, Opcao4 and Opcao5) and another call Answer with the correct answer.
I personally think that the second option would be the best, so that when I answer the question, I can pull them out of the seat and put in radio Buttons and make if
's to verify which user responded and check whether that option is correct or not.
Does anyone have any other idea that’s better?
I also thought that way Gypsy, but I thought it would hurt the performance of the system. And only one doubt there in Opcoesresposta, that attribute Guid, I never used him. He’s like a Dictionary ? That is, an array with response options. Because it has that foreach in the view to scan what is in the model.... And another, would have to put some example of code in the controller ?
– Érik Thiago
It does not harm so much. The Guid is a special type that generates a unique key and serves as the primary key. Feel free to use
int
in place if you want. I will improve the example for you.– Leonel Sanches da Silva
I get it. but I have another question... If I put all the response options in one field, how would I sweep all that content and put in a radiogroup and more, how would I see what selected is the right answer or not ?
– Érik Thiago
It would be much more complicated this way: you would have to invent a way to separate the information in order to assemble a
RadioGroup
valid and assemble the answer. There is no need to use a simpler data structure just to get efficiency.– Leonel Sanches da Silva
But that way you put it in the answer, it feels right ? You put all the response options in a single field and then assemble the radiogrouplist right ?
– Érik Thiago
So actually to "put in a single field" is riding the
RadioGroup
. What I do in the answer is simply separate the answer so that Razor can write an item fromRadioButton
by reply. The grouping takes place by the first argument of@Html.RadioGroup()
(in the case,RespostaEscolhida
).– Leonel Sanches da Silva