在Kendo Grid中显示图像:使用JSON JAVASCRIPTSERIALISER序列化或进行序列化的错误



为了显示dabatase中保存为二进制的图像,我要做以下操作:

.Columns(columns =>
{
    columns.Bound(c => c.Title).Width(420).ClientTemplate(string.Format("{0}...", "#= formatter(Title) #"));
    columns.Bound(c => c.Text).Width(900).ClientTemplate(string.Format("{0}...", "#= formatter(Text) #"));
    columns.ForeignKey(p => p.languageId, (System.Collections.IEnumerable)ViewData["lang"], "Id", "Name").Title("Language").Width(140).EditorTemplateName("LangDropDown");
    columns.Bound(p => p.Image64).ClientTemplate("<img src='data:image/png;base64,#=Image64#' />").Title("Base64 Images");
    columns.Command(command => { command.Edit(); command.Destroy(); });
})

我的模型:

[Display(Name = "Photo")]  
public byte[] img { get; set; }
public string Image64
{
    get
    {
        return img != null ? Convert.ToBase64String(img) : null;
    }
}

当我加载页面时,网格显示为空,当我尝试使用浏览器的"控制台"选项卡获取更多信息时,我会看到以下错误:

使用JSON序列化或进行序列化的错误 JavaScriptSerializer。字符串的长度超过值集 在maxjsonlength属性上。

我尝试将其添加到我的web.config:

       <system.web.extensions>
           <scripting>
               <webServices>
                   <jsonSerialization maxJsonLength="50000000"/>
               </webServices>
           </scripting>
       </system.web.extensions>

  <appSettings>
    <add key="aspnet:MaxJsonDeserializerMembers" value="2147483647" />

但是这些解决方案都没有用。欢迎任何帮助!谢谢

我通过覆盖JSON方法

找到了解决方案

最新更新