我正在使用Krajee FileInput System。我有一个表单,允许用户上传照片但不是强制性的。问题是,在编辑表单时,如果没有上传文件,我会得到以下异常。
Value cannot be null or empty.
Parameter name: contentPath
如果图像为空,我如何修改接受的代码??
我试过的代码
$(function () {
var getCaption = function (imgUrl) {
if (imgUrl != null) {
var dataArray = imgUrl.split("/");
var caption = dataArray[dataArray.length - 1];
return caption
}
}
//fileUpload plugin
$("#txtPhoto").fileinput({
showUpload: false,
initialPreview: [
'<img src="@Url.Content(Model.StudentRegistration.PhotoUrl!=null?Model.StudentRegistration.PhotoUrl:"")" class="file-preview-image" alt="' + getCaption("@Model.StudentRegistration.PhotoUrl") + '" title="' + getCaption("@Model.StudentRegistration.PhotoUrl") + '">'
],
overwriteInitial: true,
initialCaption: getCaption("@Model.StudentRegistration.PhotoUrl")
});
});
答案 0 :(得分:0)
initialPreview: [
@if (Model.StudentRegistration.PhotoUrl != null)
{
'<img src="@Model.StudentRegistration.PhotoUrl)" class="file-preview-image" alt="' + getCaption(" @Model.StudentRegistration.PhotoUrl ") + '" title="' + getCaption(" @Model.StudentRegistration.PhotoUrl ") + '">'
}
],