asp.net-mvc – How to render 2 typed views from different controllers

Question:

How do I render 2 typed views from different controllers ?

Controller:

public ActionResult Index()
    {
        Cliente cli = new Cliente();
        cli.Nome = "Al Unser";

        return View(cli);
    }

Index:

 @model MvcRazor.Entidades.Cliente

    @{
        ViewBag.Title = @Model.Nome;
    }

    <h2 id="teste">@Model.Nome</h2>

    @Html.Partial("~/Views/Shared/_Pedidos.cshtml")

    <script src="~/Scripts/Home.js"></script>

Partial View:

@model MvcRazor.Entidades.Pedido

<h1>@Model</h1>

Answer:

The correct way is to bring everything into the same Action :

public ActionResult Index()
{
    Cliente cli = new Cliente();
    cli.Nome = "Al Unser";
    cli.Pedidos = new List<Pedido> 
    {
        // Lance aqui seus pedidos
    }

    return View(cli);
}

View:

@model MvcRazor.Entidades.Cliente

@{
    ViewBag.Title = @Model.Nome;
}

<h2 id="teste">@Model.Nome</h2>

@foreach (var pedido in Model.Pedidos) 
{
    @Html.Partial("~/Views/Shared/_Pedidos.cshtml", pedido)
}

@section Scripts {
    <script src="~/Scripts/Home.js"></script>
}
Scroll to Top
AllEscort