Display two Actionresult from the same Controller on the Index page

Asked

Viewed 33 times

1

I’m already displaying a table in Index, only I want to display another table from the same controller. I created a PartialView calling for PartCorteCabos() and created a view of it. I tried to make the call using @Html.Partial(), but does not display the information coming from the database. How do I display the second table?

Controller

public class DashboardSPMController : Controller
{
    DashboardSPMRepository dashRepository = new DashboardSPMRepository();

    public ActionResult Index()
    {
        return View(dashRepository.InfoReceb());
    }

    public ActionResult PartCorteCabos()
    {
        return PartialView(dashRepository.InfoCorteCabos());
    }
}

Partcortecabos (Partial View)

@model IEnumerable<WAM.Areas.Monitoramentos.Models.Entities.DashboardSPM>

@Html.Grid(Model).Columns(column =>
   {
      column.Add(x => x.prioridade_cc).Titled("Prioridade");
      column.Add(x => x.sales_order_cc).Titled("SO's");
      column.Add(x => x.delivery_cc).Titled("Delivery");
      column.Add(x => x.material_cc).Titled("P/N");
   })

Index View

@model IEnumerable<WAM.Areas.Monitoramentos.Models.Entities.DashboardSPM>

@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/Master.cshtml";
}
        <div>
            <span class="titulo">
                <p>Status Recebimento</p>
            </span>
            <span class="size-tab">
                @Html.Grid(Model).Columns(column =>
                {
                   column.Add(x => x.material).Titled("Itens 902");
                   column.Add(x => x.lead_time).Titled("LT");
                   column.Add(x => x.lotes_nac).Titled("Lote Nacional");
                   column.Add(x => x.lotes_imp).Titled("Lote Importado");
                   column.Add(x => x.sb).Titled("SB's");
                   column.Add(x => x.danfe).Titled("DANFE's");
                })
            </span>
        </div>

        <div>
            <span class="titulo">
                <p>Corte Cabos</p>
            </span>
             @Html.Partial("PartCorteCabos")
        </div>
  • How do not display values coming from the bank ? pass the model to your view ?

  • In the first 'div' the data is displayed normally. But in the second 'div' the data is not displayed, only the column name appears but the data does not appear.

  • @Marcosbrinner managed to make it display. I changed the shape I was calling Partialview. Instead of calling it that way @Html.Partial("Partcortecabos"), which is the form in the top code, I called it @Html.Action ("Partcortecabos").

  • The model declared in Partial should not be of the same type received in InfoCorteCabos()? I see that in the controller you have two different methods and in the views you are indicating the same model

  • The data is inside only one Model that is Dashboardspm

  • But both methods, dashRepository.InfoReceb() and dashRepository.InfoCorteCabos() return a DashboardSPM? Include her structure in the question

  • Yes, both return a Dashboarsspm. I do not know if the way I did was the best, I think not, because I am still learning. But it solved my problem. If you have a better way to display the data, I would like to know to learn.

  • It wouldn’t be ideal for you to call a Renderaction(Controlleraction) in your view, where your controller would be responsible for returning to Controlleraction with your model?

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.