简体   繁体   中英

MVC3: How do I bind a model that contains a generic list of a certain class back to the controller? It always is null

The Situation

Within the BuyerOtherInfoModel there is a generic list of BuyerPropertyInfoModels which is called LinkedProperties. When I load my view the editor template iterates through this generic list and works great. But when I postback I have issues with null values.

My Problem

My model binds to the view initially perfectly but when I postback the LinkedProperties generic list is always null. How do I make my editortemplate / jquery template match up correctly on postback? Sorry if this is hard to explain please ask for clarification.

Pastes:

Model: http://pastebin.com/UemmdqSg
Editor Template: http://pastebin.com/2v0fxgiq

Sorry guys this is my first question on stackoverflow and I have attempted to search for this problem already but I have no clue where to go from here. Let me know if you need any clarification on the issue. Thanks alot!

Add a constructor for BuyerListModel:

public class BuyerListModel {
    public int FirstItemOnPage { get; set; }
    // ...
    public PagedList<BuyListItem> ListItems { get; set; }

    public BuyerListModel() {
        // When it attempts to put the BuyListItems into the collection,
        // The parameter isn't initialized, so it's internally catching
        // a null reference exception.
        ListItems = new PagedList<BuyListItem>();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM