我正在尝试通过单击替换视图中的图像。我的控制器返回一个字节数组,但视图将原始图像替换为空图像。
这是我的控制器代码:
[HttpPost]
public byte[] GetSelectedImage(string selectedImageId, string accountId, string courseId)
{
// Laden des Originalfotos
var pictures = (from ga in _db.MyPhotos
where
ga.AccountId.Equals(accountId) &&
ga.CourseId.Equals(courseId) &&
ga.SortOrder.Equals(selectedImageId)
select ga.PhotoStreamOriginal.ToArray());
var images = pictures.ToList();
byte[] imageByteArray = images.First();
return imageByteArray;
}
hier 是我在我的 Javascript 中所做的:
$('#makeMeScrollable img').live('click touchstart', function (event) {
event.preventDefault();
var selectedImage = $(this).attr('data-id');
var selectedImageId = @Html.Raw(Json.Encode(Model.SelectedImageId));
var accountId = @Html.Raw(Json.Encode(Model.AccountId));
var courseId = @Html.Raw(Json.Encode(Model.CourseId));
$.ajax({
url: '@Url.Action("GetSelectedImage", "UploadPhoto")',
dataType: 'text',
data: {selectedImageId: selectedImageId, accountId: accountId, courseId: courseId},
type: 'POST',
success: function(data) {
$('#OriginalImage').attr('src', "data:image/jpg;base64," + data);
alert("data:image/jpg;base64," + data);
}
});
});
警报也仅拍摄,data:image/jpg;base64,System.Byte[]
知道我做错了什么吗?
谢谢你的帮助