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
:
But I would like to put a button on that screen, with the Print option: Where this data was uploaded to another screen
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?
– Barbetta
Yes, Exactly.
– Rafael Passos
because the
RedirectToAction
didn’t work? He’s not carrying theViewModel
or is it because you couldn’t identify when it’s to be an impression or just the display on the screen?– Leandro Angelo
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.
– Rafael Passos
In that case you should use
return View("RelatorioTotalPorDatadois", vrDb);
– Leandro Angelo