I have this ajax call:
$.ajax({
type: "POST",
url: '/Home/Upload?customerID=' + customerID + "&questionID=" + id + "&community=" + communitySelected + "&lot=" + lotSelected,
data: formData,
dataType: 'json',
contentType: false,
processData: false,
success: function (response) {
alert('success!!');
$("#" + id).attr('disabled', false);
},
error: function (error) {
alert(error);
console.log(error);
}
});
which calls this:
[HttpPost]
public ActionResult Upload(int customerID, int questionID, string community, int lot)
{
for (int i = 0; i < Request.Files.Count; i++)
{
var file = Request.Files[i];
string path = Path.Combine(Server.MapPath("~/UploadedFiles"),
Path.GetFileName(customerID + "-" + community + lot + "-" + questionID + "-" + file.FileName));
file.SaveAs(path);
}
return Json(new { success = true },
"text/plain");
}
Now this all works on my localhost, but when I put it on a server and try to upload a file, I get a 500 error. What I am trying to do now is add error logging on the .NET side to see what exactly the problem is, so my question is how would I adjust my .NET method to show me the error.
I tried to do a try and catch like so:
[HttpPost]
public ActionResult Upload(int customerID, int questionID, string community, int lot)
{
for (int i = 0; i < Request.Files.Count; i++)
{
try
{
var file = Request.Files[i];
string path = Path.Combine(Server.MapPath("~/UploadedFiles"),
Path.GetFileName(customerID + "-" + community + lot + "-" + questionID + "-" + file.FileName));
file.SaveAs(path);
}
catch (Exception e)
{
Console.Write(e);
}
}
return Json(new { success = true },
"text/plain");
}
but how do I display the error?
Thanks,