1 namespace System.Web.Mvc
2 {
3 using System;
4 using System.Globalization;
5 /// <summary>
6 /// Fckeditor的HTMLHelper
7 /// http://chsword.cnblogs.com/
8 /// </summary>
9 static public class FckTextBoxExt
10 {
11 /// <summary>
12 /// Fckeditor的HTMLHelper,可以与同名ViewData绑定
13 /// </summary>
14 /// <param name="u">HtmlHelper</param>
15 /// <param name="name">Html的NAME</param>
16 /// <returns></returns>
17 public static string FckTextBox(this HtmlHelper u, string name)
18 {
19 return u.FckTextBox(name, null);
20 }
21 /// <summary>
22 /// Fckeditor的HTMLHelper
23 /// </summary>
24 /// <param name="u"></param>
25 /// <param name="name">Html name </param>
26 /// <param name="value">内容</param>
27 /// <returns></returns>
28 public static string FckTextBox(this HtmlHelper u, string name, object value)
29 {
30 return u.FckTextBox(name, value.ToString());
31 }
32 /// <summary>
33 /// Fckeditor的HTMLHelper
34 /// </summary>
35 /// <param name="u"></param>
36 /// <param name="name">Html name</param>
37 /// <param name="value">内容</param>
38 /// <returns></returns>
39 public static string FckTextBox(this HtmlHelper u, string name, string value)
40 {
41 if (value == null)
42 {
43 value = Convert.ToString(u.ViewDataContainer.ViewData[name], CultureInfo.InvariantCulture);
44 }
45
46 return string.Format(@"<textarea name=""{0}"" id=""{0}"" rows=""50"" cols=""80"" style=""width:100%; height: 600px"">{1}</textarea>
47 <script type=""text/javascript"">
48 var oFCKeditor = new FCKeditor('{0}') ;
49 //oFCKeditor.BasePath = sBasePath ;
50 oFCKeditor.Height=400;
51 oFCKeditor.ReplaceTextarea() ;
52 </script>
53 ", name, value);
54
55 }
56 }
57 }
用法
View页写
<%=Html.FckTextBox("content")%>即可
Controller写
ViewData["content"]="<div>....</div>";
即可与之绑定