0

I am trying to display dynamic Controls like TextBox,DropdownList,CheckBox and RadioButton (generated in Controller) in the view and post user response back from these controls(view) to post action method like any other view. Is it possible ? If yes then how can I post Response from a view with multiple partial views from the dynamic controls.

public abstract class ControlViewModel
{
    public int questionId { get; set; }
    public abstract string Type { get; }
    public bool Visible { get; set; }
    public string Label { get; set; }
    public string Name { get; set; }
    public string partialView { get; set; }          
    public string Answer { get; set; }
}

public class TextBoxViewModel : ControlViewModel
{
    public override string Type => "TextBox";
    public string Value { get; set; }
}

public class CheckBoxViewModel : TextBoxViewModel
{
    public CheckBoxViewModel()
    {
        QuestionResponses = new List<QuestionResponse>();
    }
    public override string Type => "CheckBox";
    public bool Value { get; set; }
    public List<QuestionResponse> QuestionResponses { get; set; }
}

public class DropDownListViewModel : TextBoxViewModel
{
    public DropDownListViewModel()
    {
        Values = new SelectList(new List<SelectListItem>());
    }
    public override string Type => "DropDownList";
    public SelectList Values { get; set; }
    public string selectedValue { get; set; }
}

public class RadioButtonViewModel : TextBoxViewModel
{
    public RadioButtonViewModel()
    {
        Values = new SelectList(new List<SelectListItem>());
    }
    public override string Type => "Radio";

    public SelectList Values { get; set; }
}
Aleks Andreev
  • 7,016
  • 8
  • 29
  • 37

0 Answers0