0
我使用的是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")
});
});
在哪一行,你得到这个例外? –
异常在行img src标记 – ksg
您是否在未调用'@ Url.Content'的情况下尝试它? –