Pass list objects with MVC Razor

后端 未结 3 1167
鱼传尺愫
鱼传尺愫 2020-12-11 18:48

I am using an object but inside object I have a property that is a list of objects. I want to pass that object with the list objects inside it but the list is empty when I s

3条回答
  •  被撕碎了的回忆
    2020-12-11 19:23

    Check out the BeginCollectionItem html helper available on nuget or here: https://github.com/danludwig/BeginCollectionItem

    You can see more information on the behavior on this blog: http://weblogs.asp.net/nmarun/archive/2010/03/13/asp-net-mvc-2-model-binding-for-a-collection.aspx

    The default model binder is expecting the names to come in this form:

    MemberAttendance[0].Prop = "prop"
    MemberAttendance[0].BoolProp = false
    

    so you need to name the inputs similarly:

    
    
     
    
    
    
    
    

提交回复
热议问题