2015-12-31 31 views
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") 
     }); 
    }); 
+0

在哪一行,你得到这个例外? –

+0

异常在行img src标记 – ksg

+0

您是否在未调用'@ Url.Content'的情况下尝试它? –

回答

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 ") + '">' 
      } 
     ], 
+0

谢谢你的reply.tried,但得到的错误'字符数量太多字符' – ksg

相关问题