MVC2.0 呈現斷行效果

摘要:MVC2.0呈現斷行效果

在MVC2.0裡,在textarea輸入文字後,想要表格呈現文字多行分割的效果,底下的方式是行不通,沒辦法呈現斷行的效果。

<%:ViewData["Content"].ToString().Replace("\r\n", "<br/>") %>

要用MVC提供的HTML 編碼的字串才可以呈現。

<%: MvcHtmlString.Create(ViewData["Content"].ToString().Replace("\r\n", "<br/>"))%>

 參考網址: http://msdn.microsoft.com/zh-tw/library/system.web.mvc.mvchtmlstring.create.aspx