or
Function
ImageUpload(uploadedImages
As
BO.Models.UploadedImage)
As
ContentResult
If
uploadedImages.Image.Last.ContentType.StartsWith(
"image/"
, StringComparison.OrdinalIgnoreCase)
Then
Dim
imageBytes
As
Byte
() = BO.Factory.Image.ResizeImage(194, 194, uploadedImages.Image.Last.InputStream, Drawing.Brushes.White, Drawing.Imaging.ImageFormat.Png)
Dim
thumbBytes
As
Byte
() = BO.Factory.Image.ResizeImage(100, 100, uploadedImages.Image.Last.InputStream, Drawing.Brushes.White, Drawing.Imaging.ImageFormat.Png)
BO.Factory.ContractorFactory.SaveImages(imageBytes, thumbBytes, uploadedImages.ContractorId)
End
If
Return
Content(
String
.Empty)
End
Function
Function
ImageRemove(uploadedImages
As
BO.Models.UploadedImage)
As
ContentResult
Return
Content(
String
.Empty)
End
Function
<
img
alt
=
"@Model.Name"
data-upload-image
=
"true"
src
=
"@Url.Action("
image", New With {
.controller
=
"contractor"
,
.area
=
"contractor"
,
.id
=
Model
.ContractorId})" />
@code
Dim imageUploada As Kendo.Mvc.UI.Upload = Html.Kendo.Upload().Name("Image") _
.Multiple(False) _
.Async(Function(y) y.AutoUpload(True) _
.Save("imageupload", "contractor", New With {.area = "contractor", .contractorid = Model.ContractorId}) _
.Remove("imageremove", "contractor", New With {.area = "contractor", .contractorid = Model.ContractorId})) _
.Events(Function(events) events.Success("imageUploaded").Error("onUploadError"))
imageUploada.Render()
End Code
</
div
>
<
script
>
function onUploadError(e) {
alert(e.operation)
alert(e)
alert(getFileInfo(e))
}
function imageUploaded(e) {
$("img[data-upload-image]").each(function (index) {
var url = $(this).attr("src") + '?' + Math.random() * 1000000;
$(this).attr("src", url);
});
}
function getFileInfo(e) {
return $.map(e.files, function (file) {
var info = file.name;
// File size is not available in all browsers
if (file.size > 0) {
info += " (" + Math.ceil(file.size / 1024) + " KB)";
}
return info;
}).join(", ");
}
</
script
>