【发布时间】:2026-02-11 08:50:02
【问题描述】:
我想将错误消息传递给 Blueimp jQuery File Upload 插件。我使用 ASP.NET MVC 并在出现某些情况时抛出我自己的异常(即文件不是真实图像,只有图像异常或图像太宽等)。
var file = Request.Files[i];
_service.ImageValidation(file.InputStream);
public void ImageValidation(System.IO.Stream fileStream)
{
Bitmap bmp = null;
try
{
bmp = new Bitmap(fileStream, false);
}
catch
{
throw new NoImageException();
}
if (bmp.Width > bmp.Height && (bmp.Width < 1024 || bmp.Height < 768))
throw new ImageDimensionTooSmall();
if ((bmp.Width <= bmp.Height) && (bmp.Width < 768 || bmp.Height < 1024))
throw new ImageDimensionTooSmall();
fileStream.Position = 0;
}
在客户端我尝试通过以下方式捕获错误:
$('#fileupload').fileupload({
url: '/SmartphonePhotographer/ManageFiles?ResponseID=' + ResponseID,
error: function (e, data) {
alert('error');
}
});
'data' 变量总是有 'error' 值。 'e' 有很多属性,包括 statusText='Internal server error' 和 responseText(html 页面异常)。问题 - 如何在服务器端传递错误消息以在客户端捕获它(也许,有一个 json 格式的错误,但我没有在文档中找到它)
【问题讨论】:
标签: javascript jquery asp.net-mvc blueimp