带有多行文本的Kendo MVC UI TreeList

时间:2019-06-17 05:45:27

标签: kendo-ui telerik kendo-asp.net-mvc telerik-mvc kendo-treelist

我将文本区域作为EditorTemplate(StringTextArea.cshtml)添加到TreeList。

@model string

@(Html.TextAreaFor(m => m, new { @class = "k-input k-textbox" }))

模型类

public class LevelViewModel
{
    public int Id { get; set; }
    public string LvlName { get; set; }
    [UIHint("StringTextArea")]
    public string LvlType { get; set; }
}

TreeList在编辑模式下添加文本区域,在将其保存到SQL Server 2008之前,我将LvlType中的'\ n'替换为'<br />'

LvlType = lvl.LvlType.Replace("\n", "<br />")

但是它会在TreeList中按原样显示字符串。

enter image description here

有什么方法可以使TreeList显示带有换行符的字符串?

谢谢

1 个答案:

答案 0 :(得分:0)

我第一个替换编码的<br />的想法是,实际上使它变得比((..

最好的解决方案是制作一个模板:     模板:“#= LvlType#”

使用#=#时将不编码,使用#:#时将编码! 我的测试:Telerik dojo

<html>
<head>
<base href="https://demos.telerik.com/kendo-ui/treelist/local-data-binding">
<style>html { font-size: 14px; font-family: Arial, Helvetica, sans-serif; }</style>
<title></title>
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.2.514/styles/kendo.common-material.min.css" />
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.2.514/styles/kendo.material.min.css" />
<link rel="stylesheet" href="https://kendo.cdn.telerik.com/2019.2.514/styles/kendo.material.mobile.min.css" />

<script src="https://kendo.cdn.telerik.com/2019.2.514/js/jquery.min.js"></script>
<script src="https://kendo.cdn.telerik.com/2019.2.514/js/kendo.all.min.js"></script>

</head>
<body>
    <div id="example">
        <div id="treelist"></div>

        <script>
            $(document).ready(function () {
                var dataSource = new kendo.data.TreeListDataSource({
                    data: [
                      { id: 1, Name: "Daryl <br/>Sweeney", Position: "CEO", Phone: "(555) 924-9726", parentId: null },
                    ],

                    schema: {
                        model: {
                            id: "id",
                            expanded: true
                        }
                    }
                });

                $("#treelist").kendoTreeList({
                    dataSource: dataSource,
                    height: 540,
                    columns: [
                        { field: "Position" },
                        { field: "Name", template: "#=Name#" },
                        { field: "Phone" }
                    ]
                });
            });
        </script>
    </div>
</body>
</html>