动态控件响应MVC中的动作方法?

时间:2016-06-08 14:41:38

标签: c# asp.net-mvc

我正在尝试在视图中显示动态控件,如TextBox,DropdownList,CheckBox和RadioButton(在Controller中生成),并将用户响应从这些控件(视图)发回到post动作方法,就像任何其他视图一样。可能吗 ?如果是,那么如何从具有动态控件的多个部分视图的视图中发布响应。

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; }
}

0 个答案:

没有答案