I have a button with an action :
<a id="viewlog" href="" class="btn btn-default" />
And :
$("#viewlog").bind('click', function (e) {
$.ajax({
url: "/Log/FindFile?idTraitement=" + $("#IdTraitement").val(),
success: function (data) {
if(data.success == false){
Lobibox.alert('error', { title: 'Erreur', msg: 'Fichier introuvable' });
}
else
window.location.href = "/Log/GetTraitementLogs?idTraitement=" + $("#IdTraitement").val();
},
error: function (response) {
Lobibox.alert('error', { title: 'Erreur', msg: response.responseText });
}
});
});
The action call is this, the idea is if a file is found I return true else false :
public JsonResult FindFile(int idTraitement)
{
string filename = string.Empty;
try
{
filename = new QryTraitementService().GetErrLogFilename(idTraitement);
}
catch(Exception e)
{
return Json(new { success = false, responseText = e.Message }, JsonRequestBehavior.AllowGet);
}
return Json(new { success = true }, JsonRequestBehavior.AllowGet);
}
and then, if the file is found :
public FileResult GetTraitementLogs(int idTraitement)
{
string filename = new QryTraitementService().GetErrLogFilename(idTraitement);
return File(filename,"text/csv",filename);
}
So, first thing is when I come back to client side with firefox or chrome I go to the error
in ajax but with IE I go to the success with a var success
in data
.
But the big problem is that the function always redirect me to nowhere so I fail in 404. Why the call always redirect me ? Even if I don't pass on a window.location.href
?