【发布时间】:2016-05-04 23:22:34
【问题描述】:
我有这个 ajax 调用:
$.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);
}
});
这叫这个:
[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");
}
现在这一切都在我的本地主机上运行,但是当我将它放在服务器上并尝试上传文件时,我收到 500 错误。我现在要做的是在 .NET 端添加错误日志以查看究竟是什么问题,所以我的问题是如何调整我的 .NET 方法来显示错误。
我试着像这样尝试并抓住:
[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");
}
但是如何显示错误?
谢谢,
【问题讨论】:
标签: c# jquery asp.net ajax asp.net-mvc