Link to home
Start Free TrialLog in
Avatar of Crystal Rouse
Crystal RouseFlag for United States of America

asked on

I need to pass a parameter from an MVC View to a partial View

I have a View that is the Success Page of a Form submit.  It contains a DataTable:

<div id="data">
    @Html.Table(master.Models.HTML.HtmlTable.Table.WorkOrder_ViewWorkOrders)
</div>

Open in new window


The Controller for this View is:

[HttpPost]
public JsonResult Success(int id)
{
    List<string[]> tableData = new List<string[]>();
    List<string> row = new List<string>();

    List<Success> Orders = (from x in DB.vw_Success
                                            select x).ToList();
    Orders = (from x in Orders
                    where x.ID == id
                    select x).ToList();

    for (int i = 0; i < Orders.Count(); i++)
    {
        row.Add(Orders[i].Name);
        row.Add(Orders[i].LOCATION);
        row.Add(workOrders[i].Item);

        tableData.Add(row.ToArray());
        row.Clear();
    }

    return Json(new { data = tableData });
}

Open in new window


I need to add a partial view to my Success View to show additional details about the Order at the top.
I believe I add it by adding this to the View:      @Html.Partial("~/path to my view.../Details.cshtml");

The Controller for the Details View is:

 
[HttpPost]
public ActionResult Details(int id)
{

    List<vw_Success> Orders = (from x in DB.vw_Success
                                            select x).ToList();
    Orders = (from x in Orders
                    where x.ID == id
                    select x).ToList();

    return View(Orders.OrderByDescending(x => x.ID).ToList());
}

Open in new window


A snippet of my Partial View for Details is:

@model List<master.Areas.Order.Models.vw_Success>

<div class="panel panel-info">

    <div class="panel-heading">Order Details</div>

    <div class="panel-body">

        @for (int i = 0; i < Model.Count; i++)
        {
            <div class="row" style="margin-bottom: 10px;">
                <div class="col-xs-8">
                    <span style="font-weight: bold;">Order Name: @Model[i].Name</span>
                </div>

                <div class="col-xs-4">
                    <span style="font-weight: bold;">Part #:</span>
                </div>
            </div>

Open in new window


The View contains much more but that is enough to explain my problem.
The Model is not returning anything.  I believe I need to pass the id parameter to the partial view somehow.

Thank You!
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Crystal Rouse

ASKER

Your.solution worked!