Click here to Skip to main content
15,893,508 members

Using an additional table in a MVVM Details View

Makin6425 asked:

Open original thread
Hi, at the moment I have a OrderConfirmationController which has a Details view which displays the records. At the bottom of the Details View I want to add 5 fields from another table that will be displayed in the view but not sure how to add them.

At the bottom of the last table I want to implement a separate table containing the Product_ID, Description, Price, Quantity and Total from a Sales_Order_Line table but don't know how to add it as I can only reference one table using the @model at the start of the view.

Thanks.

Here is my code for the Details controller:
C#
   public ActionResult Details(string documentNo, int documentType)
{
    // Compound key is used here so require both fields to be included in the SQL.
    Sales_Order confirmOrder = _data.Sales_Orders
       .Where(x => x.Document_Type == documentType && x.Document_No_ == documentNo)
       .FirstOrDefault();
    return View(confirmOrder);


}


Here is the code for my view:
@model SPR.Titanium.MultiChannel.ManagementConsolePortal.Sales_Order


<link href="~/Content/themes/ui-lightness/jquery-ui-1.10.3.custom.css" rel="stylesheet"     />

@section Scripts
{
@Scripts.Render("~/bundles/jqueryui");
<script src="~/js/jquery-1.9.1.js"></script>
<script src="~/js/jquery-ui-1.10.3.custom.js"></script>
<script>
    $(function () {
        $("#accordion").accordion();
    })
</script>

}

@{
ViewBag.Title = "Order Confirmation Details";
}

<h2>Order Confirmation</h2>

@using (Html.BeginForm())
{
<div id="accordion">
    <div class="editor-field">
        Billing Details:
    </div>
    <div class="editor-field">
        <table style="width:100%">
            <tr>
                <th style="width:20%">Billing Name</th>
                <td style="width:30%">@Html.EditorFor(model =>   model.Sell_to_Customer_Name)</td>
                <th style="width:20%">Address</th>
                <td style="width:30%">@Html.EditorFor(model => model.Bill_to_Address).  </td>
                <th style="width:20%">Address 2</th>
                <td style="width:30%">@Html.EditorFor(model => model.Bill_to_Address).  </td>
            </tr>
            <tr>
                <th style="width:20%">City</th>
                <td style="width:30%">@Html.EditorFor(model => model.Bill_to_City)</td>
                <th style="width:20%">County</th>
                <td style="width:30%">@Html.EditorFor(model => model.Bill_to_County).</td>
                <th style="width:20%">Post Code</th>
                <td style="width:30%">@Html.EditorFor(model => model.Bill_to_Post_Code)</td>
            </tr>
            <tr>
                <th style="width:20%">Country</th>
                <td style="width:30%">@Html.EditorFor(model => model.Bill_to_Country_Region_Code)</td>
            </tr>

        </table>
    </div>
    <div class="editor-label">
        Delivery Details
    </div>
    <div class="editor-field" aria-readonly="true">
        <table style="width:100%">
            <tr>
                <th style="width:20%">Delivery Name</th>
                <td style="width:30%">@Html.EditorFor(model => model.Ship_to_Contact_Name)</td>
                <th style="width:20%">Address</th>
                <td style="width:30%">@Html.EditorFor(model => model.Ship_to_Address)</td>
                <th style="width:20%">Address 2</th>
                <td style="width:30%">@Html.EditorFor(model => model.Ship_to_Address_2)</td>
                </tr>
            <tr>
                <th style="width:20%">City</th>
                <td style="width:30%">@Html.EditorFor(model => model.Ship_to_City)</td>
                <th style="width:20%">County</th>
                <td style="width:30%">@Html.EditorFor(model => model.Ship_to_County)</td>
                <th style="width:20%">Post Code</th>
                <td style="width:30%">@Html.EditorFor(model => model.Ship_to_Post_Code)</td>
            </tr>
            <tr>
                <th style="width:20%">Country</th>
                <td style="width:30%">@Html.EditorFor(model => model.Ship_to_Country_Region_Code)</td>
            </tr>
            </table>
    </div>

</div>    
Tags: C#, MVC, MVVM, Controller, DetailsView

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900