MVC post a list of complex objects

前端 未结 5 1896
眼角桃花
眼角桃花 2020-11-30 06:41

I have a FeedbackViewModel that contains a list of questions:

public class FeedbackViewModel
{
    public List Questions { get; set;         


        
5条回答
  •  一生所求
    2020-11-30 07:26

    Thanks for pointing me in the right direction with this post. I was struggling to get the syntax right for binding a non-sequential IDictionary object. Not sure this is 100% correct, but this Razor code worked for me:

    
    
    @Html.CheckBox(name: "MyDictionary[ABC].Value", isChecked: Model.MyDictionary["ABC"], htmlAttributes: null)
    

    If you need a checkbox, be sure to use Html.CheckBox instead of a standard HTML checkbox. The model will blow up if a value is not provided, and Html.CheckBox generates a hidden field to ensure a value is present when the checkbox is not checked.

提交回复
热议问题