请参阅以下代码。此代码只接受 jpeg/jpg、png 格式的图片。图像大小也限制为 100KB。
@(Html.Telerik().Upload()
.Name("EmployeeImageUpload")
.Multiple(false)
.Async(async => async
.Save("SaveEmployeeImage", "Employee")
.AutoUpload(false)
)
.ClientEvents(events => events
.OnLoad("onLoad")
.OnSelect("onSelect")
.OnSuccess("onSuccess")
)
)
<script type="text/javascript">
function onLoad(e) {
$(this).find("input").attr("accept", "image\/jpeg,image\/jpg,image\/png");
}
function onSelect(e) {
if (e.files[0].size > 102400) {
alert('Image Size Should Be <= 100KB');
e.preventDefault();
return false;
}
var ext =e.files[0].extension.toLowerCase();
if ($.inArray(ext, ['.jpeg', '.jpg', '.png']) == -1) {
alert('Only Supported Extension are jpeg/jpg, png');
e.preventDefault();
return false;
}
return true;
}
</script>