Thank you for your attention!
I'm developing in ASP.NET MVC5
What happens is this: When you run tests on localhost , this code works perfectly. I can retrieve the tempdata
containing the object to send it to the View that generates the PDF. However, when I publish the project to an approval server, the call to the Controller BAIXARPDF
can not receive the tempdata
, it is null. Can anyone give me an idea of why different behavior in environments?
I make the following Ajax call:
$.ajax({
url:urlL,
async: false,
type: "POST",
data: JSON.stringify(UniformePDF),
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (iddata) {
window.location = iddata;
baixarPDF(iddata);
},
error: function (xhr, textStatus, err) {
alert(err);
},
cache: false
});
});
This call invokes Action in Controller :
public ActionResult GerarPDF(UniformePDF u)
{
TempData["teste"] = "teste";
if (u.NomePeca == null)
{
u.NomePeca = "padrao";
}
if (Request.IsAjaxRequest())
{
var urlHelper = new UrlHelper(Request.RequestContext);
ViewBag.UniformeBag = u;
TempData[u.NomePeca] = u;
TempData.Keep(u.NomePeca);
//string url = RedirectToAction("BaixarPDF", "Uniforme", new { UniformePDF = u, area = "Uniformes"})
string url = urlHelper.Action("baixarPDF", new { idUniforme = u.NomePeca });
return Json(url, JsonRequestBehavior.AllowGet);
}
return Json("OK", JsonRequestBehavior.AllowGet);
}
This Controller mounts a tempdata
and returns a Json with the URL to the next Controller that will retrieve the object within tempdata
and return a View that generates a PDF.
public ActionResult baixarPDF(string idUni)
{
bool retorno = false;
String remover, link, adicionar;
UniformePDF modeloUniforme = new UniformePDF();
if (TempData["teste"] != null)
{
modeloUniforme = TempData[Request.QueryString["idUniforme"]] as UniformePDF;
if (modeloUniforme.NomePeca == Request.QueryString["idUniforme"])
{
//var svg = Encoding.UTF8.GetString(bytes);
remover = getBetween(modeloUniforme.Desenho, "<svg", "<g");
link = "http:" + "//www.w3.org/2000/svg";
adicionar = "<svg xmlns=\"" + link + "\" width=\"500px\" height=\"500px\" viewBox=\"0 0 1000 1000\">";
if (remover.Length != 0)
{
modeloUniforme.Desenho = modeloUniforme.Desenho.Replace(remover, adicionar);
}
string svgString = modeloUniforme.Desenho;
string base64 = CreateBase64Image(svgString);
modeloUniforme.DirBase64 = base64;
retorno = true;
}
}
if (retorno)
{
return new PartialViewAsPdf("Modelo", modeloUniforme)
{
PageSize = Rotativa.Options.Size.A4,
FileName = modeloUniforme.NomePeca + ".pdf"
};
}
else
{
return Json(retorno, JsonRequestBehavior.AllowGet);
}
}