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
?
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.
Comments