I have created a MVC 5 application where I am creating a custom purchasing system.
My View model is generated based on the contents of an SQL Database. The database uses a Single Primary Key for a Purchase Order with some basic data. In addition to the basic data each PO can have multiple items within that purchase order. This creates a relationship where there can be N items to a single Purchase.
When I am doing a form Submit the sending of the Purchase Order specific information, ie using TextBoxFor(m => m.Date), works fine. However I cannot seem to pass the list of all the Items within it. For example when I am doing @Html.TextBoxFor(m => m.Details.ItemName) it is not populating the section in the model during the POST.
I have tried sending all the information using @Html.TextBoxFor(m => m.Details) but it throws errors as the TextBoxFor cannot handle these data types.
I am after a system where I can edit a purchase order model by adding or removing items without committing to my database until the 'save' button is pressed.
My View Model example is
public class PurchasingEditModel
{
public tbl_PurchaseOrder PurchaseOrder;
}
Purchase order in itself has a link to PurchaseOrderDetails (within SQL) via a Foreign key reference of the Purchase Order. This creates the Many Items to One PO.
The controller for the edit page is
public ActionResult Edit(int? pkPurchaseOrder)
{
model.PurchaseOrder = db.PurchaseOrder.Where(x => x.pkPurchaseOrder == pkPurchaseOrder);
return View(model);
}
This together with a standard Edit.cshtml using @Html.TextBoxFor(m => m. all works fine with the display portion, until I want to post the multiple items within the sub-table.
Really the easiest way for me to handle this would be to pass the all contents of model during the display, which has all the elements of the items within the PO, to the POST function.
Any guidance you can give is appreciated.