【发布时间】:2015-07-22 08:38:54
【问题描述】:
我收到“内部服务器错误 500”。
我无法点击操作,当我检查元素时它给出“内部服务器错误 500”。
它在本地运行良好,但是当我在客户端服务器上部署/发布它时,它不会点击 URL。
我不知道出了什么问题。
这是我的 AJAX:
jQuery2(document).ready(function () {
jQuery2('#fileupload').fileupload({
dataType: 'json',
type: "POST",
url: '@Url.Action("UploadExcelFile", "PurchaseOrder")',
contentType: "application/json; charset=utf-8",
autoUpload: true,
done: function (e, data) {
jQuery2('#filepath').val(data.result.FileName);
},
error: function (e, data) {
alert(e.error);
}
});
});
这是控制器动作
[HttpPost]
public ContentResult UploadExcelFile(string filepath, LapTopDetail REC)
{
//var fileSavePath="";
DataTable dt_Excel_Data = null;
string savedFilePath = "";
string FileName = "";
int count = 0;
try
{
foreach (string file in Request.Files)
{
HttpPostedFileBase hpf = Request.Files[file] as HttpPostedFileBase;
if (hpf.ContentLength == 0)
continue;
savedFilePath = Path.Combine(Server.MapPath("~/Attachments/LapTopDetailFiles/"), Path.GetFileName(hpf.FileName));
FileName = hpf.FileName;
hpf.SaveAs(savedFilePath); // Save the fil
}
BllClsPurhcaseOrder objclsPO = new BllClsPurhcaseOrder();
FileStream stream = System.IO.File.Open(savedFilePath, FileMode.Open, FileAccess.Read);
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
DataSet result = excelReader.AsDataSet();
excelReader.IsFirstRowAsColumnNames = true;
DataSet resultDs = excelReader.AsDataSet();
SetTargetPriceDT REC_DT = new SetTargetPriceDT();
DataTable dt = new DataTable();
dt_Excel_Data = resultDs.Tables[0];
if (dt_Excel_Data.Rows.Count > 0)
{
int intCondition = 9;
int POID = Convert.ToInt32(REC.PO_ID);
count = objclsPO.SaveTempExcelFile(intCondition, POID, dt_Excel_Data);
}
return Content("{\"FileName\":\"" + FileName + "\",\"RowsEffected\":\"" + count + "\",\"Item_Original_SrNo\":\"" + string.Format("{0} bytes", count) + "\"}", "application/json");
}
catch (Exception ex)
{
return Content("{\"FileName\":\"" + ex.Message + "\",\"RowsEffected\":\"" + count + "\",\"Item_Original_SrNo\":\"" + string.Format("{0} bytes", count) + "\"}", "application/json");
}
}
【问题讨论】:
-
使用
error: function (jqXHR,errorResponse,error) {console.log(jqXHR.responseText);}记录您遇到的错误并告诉我! -
返回 HTTP 错误 404.0 - Not Found 您要查找的资源已被删除、更改名称或暂时不可用。
-
这意味着
url没有找到...做一件事将您的url更改为正常的url: '/PurchaseOrder/UploadExcelFile',并将dataType更改为text而不是json
标签: ajax asp.net-mvc-4