ASP.NET MVC - Can't bind array to view model

后端 未结 3 874
甜味超标
甜味超标 2020-12-09 02:35

I have a view model with a from that includes a set of checkboxes. I need the check boxes to map to an array when binding in the post back method of my controller.

H

相关标签:
3条回答
  • 2020-12-09 03:13

    Set the name of the input types to all be the same. You can also create a custom model binder if you are trying to bind a more complex model than just a list. Here is an excellent article on the different ways to bind to your models

    Various Model Binding techniques

    0 讨论(0)
  • 2020-12-09 03:27

    I always come back to Phil Haack's post about model binding a list. In addition, I always define my own index because my user's will alter the list on the client side then post back the changes.

    http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx

    0 讨论(0)
  • 2020-12-09 03:29
    <input type="checkbox" id="[@i]" name="ChosenTestCollectionIds" value="@testCollection.Id" />
    
    0 讨论(0)
提交回复
热议问题