I have a project utilizing ASP.NET MVC and Razor page layouts. The page in question will be a survey whose questions, datatypes, and answers have been configured by an admin user and retrieved from a database. For example:

public class ExampleViewModel 
    //the user define dquestion
    public string Question1Text { get; set; }

    //this is an enum with "Text","YesNo","DropDown"
    public AnswerType Question1Type { get; set; } 

    //this would hold options for the drop down list
    public string Question1Options { get; set; }

    //the user input answer
    public string Question1Answer { get; set; }

What I am not sure is how to structure the Razor view to create the appropriate type of form input field depending on the AnswerType. I seem to recall something about creating templates for the various DataType() annotations but I am not sure where to start looking at that and if that applies in this case?

As always any advice in solving this issue is appreciated.

Related posts

Recent Viewed