Model Binding to an object with a collection

Yoav

I recently asked this question about binding to a collection and got an answer that helped me a lot. Now, I have a new model that looks like this(trimmed version):

public class Order
{
    public int OrderId { get; set; }
    public string OrderName { get; set; }
    public string Comments { get; set; }

    public ICollection<OrderItems> OrderItems { get; set; }
}

public class OrderItems
{
    public int OrderItemId { get; set; }
    public int OrderId { get; set; }
    public string ItemName { get; set; }
}

So I want to have 2 Inputs for the OrderName and Comments and for the OrderItems I dynamically create Tables with Text Inputs.
So if I use this syntax to bind to a collection:

<input type='text' name='OrderItem[1].ItemName'/>  

how do I do it in a scenario where my collection is only one of the properties in my Model?

Nic

YOu can try this :

@model IList<CyberSystems.UI.Controllers.System.PurchaseOrderControllers.PurchaseOrderController.Order>
           @for (int i = 0; i < Model.Count; i++)
           {
               @Html.TextBoxFor(c=>Model[i].OrderName)

                   for (int ii = 0; ii < Model[i].OrderItems.Count; ii++)

                   {
                       @Html.TextBoxFor(c=>Model[i].OrderItems[@ii].ItemName)
                   }

           }

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Binding WPF ListView to an Object with Child Collection

From Dev

Spring file upload not binding to model attribute object

From Dev

Kendo Ui Model Binding 3 level Object

From Dev

Model binding doesn't work for complex object

From Dev

Model binding issues with Kendo complex object

From Dev

WebAPI Custom Model binding of complex abstract object

From Dev

Angularjs select ng-model binding for object

From Dev

MVC manually serializing complex object or model binding

From Dev

ASP.MVC Settings Object Model Binding

From Dev

MVC manually serializing complex object or model binding

From Dev

Pass an object to a route parameter without model binding

From Dev

ASP.NET MVC Model Binding with jQuery ajax request for collection

From Dev

ASP.NET MVC/Web API model binding item to collection

From Dev

Object reference not set to an instance of an object when using custom model binding

From Dev

Binding a Model class object to Kendo Grid using JSON result

From Dev

Object is null after model binding in Web API, using POSTMAN

From Dev

Laravel 5: route-model-binding not recognizing object

From Dev

ASP.Net MVC Model Binding Complex Object using GET

From Dev

Data binding: property of model object changes from integer to string

From Dev

WPF ItemsControl binding not updating when bound to an ObservableCollection in an object in the View Model

From Dev

Model Binding with Forms: IEnumerable<ModelName> vs. IEnumerable<Object>

From Dev

Syntax error when binding a model object to a JavaScript array

From Dev

Asp.net C# model object binding

From Dev

Binding a Model class object to Kendo Grid using JSON result

From Dev

Preserving Custom Object Types When Binding Using ng-model

From Dev

MVC Model binding returns Id list instead of object

From Dev

Laravel 5: route-model-binding not recognizing object

From Dev

Model binding with a sub model

From Dev

MVC Form Model returning null for complex object collection

Related Related

  1. 1

    Binding WPF ListView to an Object with Child Collection

  2. 2

    Spring file upload not binding to model attribute object

  3. 3

    Kendo Ui Model Binding 3 level Object

  4. 4

    Model binding doesn't work for complex object

  5. 5

    Model binding issues with Kendo complex object

  6. 6

    WebAPI Custom Model binding of complex abstract object

  7. 7

    Angularjs select ng-model binding for object

  8. 8

    MVC manually serializing complex object or model binding

  9. 9

    ASP.MVC Settings Object Model Binding

  10. 10

    MVC manually serializing complex object or model binding

  11. 11

    Pass an object to a route parameter without model binding

  12. 12

    ASP.NET MVC Model Binding with jQuery ajax request for collection

  13. 13

    ASP.NET MVC/Web API model binding item to collection

  14. 14

    Object reference not set to an instance of an object when using custom model binding

  15. 15

    Binding a Model class object to Kendo Grid using JSON result

  16. 16

    Object is null after model binding in Web API, using POSTMAN

  17. 17

    Laravel 5: route-model-binding not recognizing object

  18. 18

    ASP.Net MVC Model Binding Complex Object using GET

  19. 19

    Data binding: property of model object changes from integer to string

  20. 20

    WPF ItemsControl binding not updating when bound to an ObservableCollection in an object in the View Model

  21. 21

    Model Binding with Forms: IEnumerable<ModelName> vs. IEnumerable<Object>

  22. 22

    Syntax error when binding a model object to a JavaScript array

  23. 23

    Asp.net C# model object binding

  24. 24

    Binding a Model class object to Kendo Grid using JSON result

  25. 25

    Preserving Custom Object Types When Binding Using ng-model

  26. 26

    MVC Model binding returns Id list instead of object

  27. 27

    Laravel 5: route-model-binding not recognizing object

  28. 28

    Model binding with a sub model

  29. 29

    MVC Form Model returning null for complex object collection

HotTag

Archive