How to render 2 typed view of different controllers

3

How do I render 2 typed view of 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>
    
asked by anonymous 20.08.2016 / 04:17

1 answer

1

The right 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>
}
    
19.09.2016 / 17:35