在全日历中去净化 HTML

发布于 2024-10-08 02:56:42 字数 2045 浏览 8 评论 0原文

我在 asp.net 中使用 fullcalendar。我需要让它在月视图上显示时间和位置。我尝试过使用:

cevent.title = cevent.title + "At: " + (string)reader["Location"] + "<br>";

但它正在净化 HTML 并显示
而不是应用换行符。我怎样才能强制它使用 HTML?

谢谢,

我已经尝试过 HTML 编码和解码,并使用 /n 非这些工作。显然 cevent.description 可以接受 HTML 标签,但不能接受 cevent.title 这是我正在使用的更多代码。

public static List<CalendarEvent> getEvents(DateTime start, DateTime end)
{

    List<CalendarEvent> events = new List<CalendarEvent>();
    SqlConnection con = new SqlConnection(connectionString);
    SqlCommand cmd = new SqlCommand("SELECT eventNumber, details, event, BeginDate, BeginTime, EndDate, EndTime, Location FROM events where BeginDate>=@start AND EndDate<=@end", con);
    cmd.Parameters.AddWithValue("@start", start);
    cmd.Parameters.AddWithValue("@end", end);

    using (con)
    {
        con.Open();
        SqlDataReader reader = cmd.ExecuteReader();
        while (reader.Read())
        {
            CalendarEvent cevent = new CalendarEvent();
            cevent.id = (int)reader["eventNumber"];
            cevent.title = (string)reader["event"];
            cevent.description = "<B>" + cevent.title + "</B><br/><br/>";
            if (!string.IsNullOrEmpty((string)reader["BeginTime"]))
            {
                cevent.description = cevent.description + (string)reader["BeginTime"] + " - " + (string)reader["EndTime"] + "<br>";
            }
            if (!string.IsNullOrEmpty((string)reader["Location"]))
            {
                cevent.description = cevent.description + "At: " + (string)reader["Location"] + "<br>";
            }
            cevent.description = cevent.description + (string)reader["details"];

            cevent.start = (DateTime)reader["BeginDate"];
            cevent.end = (DateTime)reader["EndDate"];
            events.Add(cevent);
        }
    }
    return events;
}

cevent.description 与
标签一起正常工作,但 cevent.title 只是显示它们。

I am using fullcalendar in asp.net. I need to have it display the time and location on the month view. I have tried using:

cevent.title = cevent.title + "At: " + (string)reader["Location"] + "<br>";

but is is purifying the HTML and displaying <br /> rather then applying the line break. How can I force it to use the HTML?

Thank you

I have tried HTML encoding and decoding and using /n non of these work. Apparently cevent.description can accept HTML tags but not cevent.title Here is more of the code I am using.

public static List<CalendarEvent> getEvents(DateTime start, DateTime end)
{

    List<CalendarEvent> events = new List<CalendarEvent>();
    SqlConnection con = new SqlConnection(connectionString);
    SqlCommand cmd = new SqlCommand("SELECT eventNumber, details, event, BeginDate, BeginTime, EndDate, EndTime, Location FROM events where BeginDate>=@start AND EndDate<=@end", con);
    cmd.Parameters.AddWithValue("@start", start);
    cmd.Parameters.AddWithValue("@end", end);

    using (con)
    {
        con.Open();
        SqlDataReader reader = cmd.ExecuteReader();
        while (reader.Read())
        {
            CalendarEvent cevent = new CalendarEvent();
            cevent.id = (int)reader["eventNumber"];
            cevent.title = (string)reader["event"];
            cevent.description = "<B>" + cevent.title + "</B><br/><br/>";
            if (!string.IsNullOrEmpty((string)reader["BeginTime"]))
            {
                cevent.description = cevent.description + (string)reader["BeginTime"] + " - " + (string)reader["EndTime"] + "<br>";
            }
            if (!string.IsNullOrEmpty((string)reader["Location"]))
            {
                cevent.description = cevent.description + "At: " + (string)reader["Location"] + "<br>";
            }
            cevent.description = cevent.description + (string)reader["details"];

            cevent.start = (DateTime)reader["BeginDate"];
            cevent.end = (DateTime)reader["EndDate"];
            events.Add(cevent);
        }
    }
    return events;
}

cevent.description functions properly with the
tages but cevent.title simply displays them.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

岁月染过的梦 2024-10-15 02:56:42

你尝试过吗?

cevent.title += "At: " + Server.HtmlDecode( (string)reader["Location"] + "<br>" );

或者

您可能需要完整的参考

HttpContext.Current.Server.HtmlDecode()

尝试使用 Environment.NewLine,如下所示:

cevent.title += "At: " + Server.HtmlDecode( ( string)reader["位置"] + Environment.NewLine);

Have you tried?

cevent.title += "At: " + Server.HtmlDecode( (string)reader["Location"] + "<br>" );

or

You might need the full reference

HttpContext.Current.Server.HtmlDecode()

Try using Environment.NewLine as shown below:

cevent.title += "At: " + Server.HtmlDecode( (string)reader["Location"] + Environment.NewLine);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文