1
Thank you in advance for your attention!
I am developing in ASP.NET MVC5
What happens is this: when the tests are carried out in the 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 on an approval server, the call to the Controller BAIXARPDF
cannot receive the tempdata
, it is null. Someone can give me an idea of why the different behavior in the environments?
I make the following call Ajax:
$.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 calls the following Action in the 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);
}
That one Controller rides a tempdata
and returns a Json with the URL to the next Controller that will retrieve the object inside the 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);
}
}
In the console from the browser you receive some error while calling the query
ajax
? What value is being passed onurlL
?– Randrade