Load data from one action to another

Asked

Viewed 200 times

0

I have a Action HttpGet, where that Action receives two parameters, dataInicial, and dataFinal, this generates a report, in the same Action. only that I would like to send this data (List), to another screen, where it is already ready for printing in A4 size, I would like to know just how to send this data to that other view, I tried to use the return RedirectToAction("RelatorioTotalPorDatadois", vrDb); but it didn’t work out.

public ActionResult RelatorioData(DateTime? dataInicio, DateTime? dataFim)
{
    ViewBag.dataInicial = dataInicio;
    ViewBag.dataFinal = dataFim;

    if (dataInicio == null && dataFim == null)
    {
        var vrDb = db.VrDb.Where(v => v.DataSolicitacao >= dataInicio && v.DataSolicitacao <= dataFim).OrderBy(v => v.DataSolicitacao).ToList();
        return View(vrDb);
    }

    else
    {
        var vrDb = db.VrDb.Where(v => v.DataSolicitacao >= dataInicio && v.DataSolicitacao <= dataFim && v.Situacao == Situacao.Finalizado).OrderBy(v => v.DataSolicitacao).ToList();
        var data = dataInicio;
        var dataF = dataFim;

        var tot = db.VrDb.Sum(v => v.Mv.Consumo); //Mostra o Total gasto

        if (tot == 0)
        {
            ViewBag.Total = "0";
        }
        else
        {
            ViewBag.Total = tot;
        }

        var abastecido = db.VrDb.Sum(v => v.Mv.CombustivelAbastecido);
        if (abastecido == 0)
        {
            ViewBag.Abastecido = "0";
        }
        else
        {
            ViewBag.Abastecido = abastecido;
        }

        ViewBag.ListaDb = vrDb;
        return View(vrDb);
        //return RedirectToAction("RelatorioTotalPorDatadois", vrDb);

    }
}

This is the screen of this Action: inserir a descrição da imagem aqui

But I would like to put a button on that screen, with the Print option: Where this data was uploaded to another screen

inserir a descrição da imagem aqui

  • I edited your question to make it more direct, remember that there is no stupid question!! , now about your problem, later I try to elaborate an answer, but from what I saw, you click button, is loaded a screen with the list and on this screen with the list you want another button to print, correct?

  • Yes, Exactly.

  • because the RedirectToAction didn’t work? He’s not carrying the ViewModel or is it because you couldn’t identify when it’s to be an impression or just the display on the screen?

  • When I use redirectAction, I pass the view and the object. However, this is the URL that appears: http://localhost:49756/Vr/Reportarysorted? Capacity=4&Count=4. And the error is the same as when you do not find a page: Server Error in the Application '/'. Return Redirecttoaction("Reporteriototalpordatais", vrDb); When the screens, when I use Redirecttoaction, the first screen only appears so that I can fill in the date, and when I send, it already redirects to the second screen, where it is already in A4 format.

  • In that case you should use return View("RelatorioTotalPorDatadois", vrDb);

1 answer

1


To be able to pass objects between Views or has to be:

Tempdata using Keep() and Peek() or using Session, because the view only reflects the information that is sent by the action. To pass objects from View to View only know these options.

Browser other questions tagged

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