当数据具有html标记时,jqGrid添加功能不起作用(如<br/>)

时间:2013-03-16 04:59:32

标签: asp.net-mvc jqgrid

当数据包含html标记时,

jqGrid添加和编辑功能无效。喜欢“br”“p”标签 如果我给autoencode:true。然后编辑和添加功能正常工作。但它显示为一个字符串。

例如: 嗨Ram“html br tag”你好吗?我的jqGrid应显示为

嗨拉姆你好吗

如果我没有给autoencode:true,则添加和编辑功能无效。

我的代码是:

<script type="text/javascript">

$(function () {

    $("#divId").jqGrid({
    colNames:['mailSub','mailBody'],
     colModel: [

                    { name: 'mailSub', index: 'mailSub', sortable: true, align: 'left', width: '150',
                        editable: true, edittype: 'text',search:true,searchoptions:{sopt:['eq']}

                    },
                    { name: 'mailBody', index: 'mailBody', sortable: true, align: 'left', width: '300',
                        editable: true, edittype: 'text',search:true,searchoptions:{sopt:['eq']}

                    } 

              ],

        pager: jQuery('#pager'),
        sortname: 'MessageKey',
        rowNum: 15,
        rowList: [15, 20, 25],
        sortorder: "desc",
        height: 340,
        viewrecords: true,
        rownumbers: true,
        caption: 'Messages',
        width: 660,
        url: "@Url.Content("url given")",
        editurl:"@Url.Content("EditUrl given")",
        datatype: 'json',
        mtype: 'GET'

    })
     jQuery("#divId").jqGrid('navGrid', '#pager', { edit:true, add: true, del: false, search: true, refresh: true },
        { closeOnEscape: true, reloadAfterSubmit: true, closeAfterEdit: true, left: 400, top: 300 },
        { closeOnEscape: true, reloadAfterSubmit: true, closeAfterAdd: true, left: 450, top: 300, width: 520 },
        { closeOnEscape: true, reloadAfterSubmit: true, left: 450, top: 300 },
        {closeAfterSearch:true,closeAfterReset:true,left: 450, top: 300});
});

4 个答案:

答案 0 :(得分:2)

在jqGrid中将属性命名为

autoencode: true

上面的属性用于编码数据。现在在控制器动作方法中解码现有的编码数据。

 String decodedText = HttpUtility.HtmlDecode(encoded_string);

答案 1 :(得分:0)

在网格选项中尝试autoencode: true,

答案 2 :(得分:0)

设置colmodel datatype ='html'

答案 3 :(得分:0)

在JQGrid列中添加html标记,您希望将相应列的数据类型设置为html。

datatype ='html'