Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble loading a child model in MVC 4
    primarykey
    data
    text
    <p>I have an OrderViewModel that includes an instance of a child _DetailsViewModel. The OrderViewModel has order header information and the _DetailsViewModel holds order detail information. Despite being separate Models, both have the same single data source..the Orders table. The reason that the details are in their own View Model is that those fields are reused on a different View, in the same visual arrangement, so I'm putting them in a Partial View to be reused as needed. Here is an idea of my main and child View Models:</p> <pre><code>public class OrderViewModel { public string OrderNum { get; set; } public string CustonerName{ get; set; } public double SalesPrice{ get; set; } public _Details Details { get; set; } } public class _DetailsViewModel { public string PhoneNum { get; set; } public string ItemNum { get; set; } public double Quantity { get; set; } public string PayMethod{ get; set; } public string Comments { get; set; } } </code></pre> <p>Within my controller I call a service that returns all data from the Orders table and returns a List of Order Entities. </p> <pre><code>orderService = new OrderService(); var orders = orderService.GetOrderInfo(StoreNum); </code></pre> <p>From there I use Omu.ValueInjecter to inject the results into the main View Model.</p> <pre><code>var orderViewModel = orders .Select(x =&gt; new OrderViewModel().InjectFrom(x)).Cast&lt;OrderViewModel&gt;() .ToList(); return View(orderViewModel); </code></pre> <p>I need to also populate the _Details model so that I can pass it to the Partial View from within my main Order View...like below:</p> <p>@Html.Partial("_OrderDetails", Model._Details)</p> <p>Is there a way to populate the _Details Model from the single service call that is already populating the main Order Model? Will I have to add the _Details properties to the main Order View and then iterate the Order view to set each field of the corresponding _Details Model manually? Surely I'm missing something.</p> <p>Thanks...</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload