How to handle multiple instances of a model on one view

Programming in How to handle multiple instances of a model on one view on newest questions tagged – Stack Overflow

I have a model class called DeviceType that is something like this:

public class DeviceType
    int ID { get; set; }
    String Type { get; set; }
    String Description { get; set; } 
    EntityCollection<AttributeDefinition> AttributeDefinitions { get; set; }

AttributeDefinition is defined like this:

public class AttributeDefinition
    int ID { get; set; }
    String Name { get; set; }
    bool IsPrivate { get; set; }
    bool IsInherited { get; set; }

I’m trying to create a view to edit the details for a DeviceType. Within that view I want a table with each AttributeDefinition as an editable row so that you can update each AttributeDefinition on the same page.

I tried to follow this post, however I get this error:

The EntityCollection has already been initialized. The
InitializeRelatedCollection method should only be called to initialize
a new EntityCollection during deserialization of an object graph.

Is there a way to do this without resorting to something like AutoMapper? Maybe using the FormCollection or using a ViewModel?

See Answers

Programming in programming-in-asp-net-mvc

Leave a Reply