我使用Valums AjaxUpload在我的ASP.NET MVC 3应用程序中上传文件。
new AjaxUpload($('input.partupload'), {
autoSubmit: true,
action: '/AdminPanel/Car/UploadPart',
onSubmit: function (file, ext) {
if (!(ext && /^(zip)$/.test(ext.toLowerCase())))
{
$('#hinf').fadeIn('slow');
$('#hinf').html("Please, upload only Zip files!!");
return false;
}
},
data: { path: directoryPath,parentName : part, carId: @Model.carID, color: color },
onComplete: function (file,response) {
var model = file.replace('.zip','');
if(response=="true")
{
alert(response);
createTree(part, model + '*' + part);
}
else
{
alert(response);
alert("Error during process");
}
}
});
在我的控制器中我有
HttpPostedFileBase file = Request.Files[0];
if (...)
{
//Here my alert fires and onComplete is OK
return Content("true");
}
else
{
//FAIL!!! Nothing is happened in OnComplete!!!!!!
return Content("false");
}
所以,我不明白返回“真实”或“假”有什么区别......为什么我第一次看到结果,第二次看不到......需要你的帮助))) )
答案 0 :(得分:0)
所以,它完美无缺!!!
HttpPostedFileBase file = Request.Files[0];
if (...)
{
return Content("true");
}
else
{
//WORKS!!!!
return Content("error");
}