How do I dynamically add and remove line items from an ASP.NET MVC view?
- by Mike Roosa
I have a PurchaseOrder model:
public class PurchaseOrder
{
public string OrderNumber { get; set; }
public string Customer { get; set; }
public IList<LineItem> Lines { get; set; }
}
and a LineItem class:
public class LineItem
{
public string PartNumber { get; set; }
public int Quantity { get; set; }
}
What I want to do is on my view for the PurhcaseOrder Create action, I need a section for line items. The user should be able to add a new line, remove a line, then submit. One caveat is the PartNumber needs to be a dropdown list of valid parts.
What can I do to accomplish what I'm looking for?