文本编辑器 - Asp.net mvc

时间:2010-09-15 22:39:09

标签: asp.net-mvc

我正在为我的asp.net mvc项目寻找文本编辑器。我能找到很多文本编辑器,效果非常好。

我正在寻找的是一个只接受像“我是超人”这样的regualr角色的编辑。 我不想将“<p><strong>I am a superman</strong></p>”保存到我的SQL表中,因为我必须通过文本框显示它(例如:<%= Html.TextBox("Remark", Model.empExperience.Remark)%>)。

让我知道。

2 个答案:

答案 0 :(得分:2)

看到您不希望允许HTML,最好的办法是简单地从提供的输入中删除HTML。对于这类事情,没有必要实现自定义文本编辑器。

查看:How can I strip HTML tags from a string in ASP.NET?

答案 1 :(得分:1)

这就是你如何做到的(总结Nathan提供的链接上的答案):

    private static readonly Regex StripHtml = new Regex("<[^>]*>", RegexOptions.Compiled);

    /// <summary>
    ///     Strips all HTML tags from the specified string.
    /// </summary>
    /// <param name = "html">The string containing HTML</param>
    /// <returns>A string without HTML tags</returns>
    public static string StripHtmlTags(string html)
    {
        if (string.IsNullOrEmpty(html))
            return string.Empty;

        return StripHtml.Replace(html, string.Empty);
    }