【问题标题】:Display Image in Kendo Grid : Error during serialization or deserialization using the JSON JavaScriptSerializer在 Kendo Grid 中显示图像:使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错
【发布时间】:2023-03-30 14:23:01
【问题描述】:

为了在 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 进行序列化或反序列化时出错 JavaScript 序列化器。字符串长度超过设置的值 在 maxJsonLength 属性上。

我试图在我的 web.config 中添加这个:

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

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

但是这些解决方案都不起作用。欢迎任何帮助! 谢谢

【问题讨论】:

  • 我找到了覆盖json方法的解决方案

标签: c# json asp.net-mvc-4 telerik web-config


【解决方案1】:

我通过覆盖json方法找到了解决方案

【讨论】:

    猜你喜欢
    • 2021-09-02
    • 2015-01-11
    • 2011-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-07
    • 1970-01-01
    相关资源
    最近更新 更多