I have a MVC Project.
I have questions in a database that I want my users to answer. I have them in the database because they need to be able to be dynamic. The user needs to submit an answer for each question. So when the view displays, it shows the question and a textbox for each question.
What would the best way to go about doing this as I do not want to hard code in the question like @Html.textBox(“Question1”) etc.
- Question 1 [__textbox1___]
- Question 2 [__textbox2___]
… etc.
I’d probably have a ViewModel that contains a collection of a custom QuestionResponder type.
Then you can create the display items you require for your new view model.
Alternartively you can create an EditorTemplate to avoid looping in your view:
Insdie
~/Views/Shared/EditorTemplates/add a new view calledQuestionResponder(the name of your custom class).Inside that template you can then add:
While you’ll then call from your original view: