using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Web.Mvc; using System.Web; namespace Bowin.Web.Controls.Mvc { public class RichText : BaseFormControl { public int? Width { get; set; } public int? Height { get; set; } public string Value { get; set; } public override string Render() { //TagBuilder tabBuilder = new TagBuilder("script"); //tabBuilder.MergeAttributes(GetPropertyList()); //if (this.Attributes != null) //{ // tabBuilder.MergeAttributes(this.Attributes); //} //tabBuilder.InnerHtml = HttpContext.Current.Server.HtmlDecode(this.Value); //return tabBuilder.ToString(TagRenderMode.Normal); TagBuilder tabBuilder = new TagBuilder("textarea"); tabBuilder.MergeAttributes(GetPropertyList()); if (this.Attributes != null) { tabBuilder.MergeAttributes(this.Attributes); } tabBuilder.InnerHtml = HttpContext.Current.Server.HtmlDecode(this.Value); return tabBuilder.ToString(TagRenderMode.Normal); } protected IDictionary GetPropertyList() { var dictPropertyList = new Dictionary(); dictPropertyList.Add("class", string.Format("easyui-richtext {0}", string.IsNullOrEmpty(this.CssClass) ? "" : this.CssClass)); //dictPropertyList.Add("type", "text/plain"); if (!string.IsNullOrEmpty(this.ID)) dictPropertyList.Add("id", this.ID); if (!string.IsNullOrEmpty(this.Name)) dictPropertyList.Add("name", this.Name); if (!string.IsNullOrEmpty(this.Title)) dictPropertyList.Add("title", this.Title); if (this.IsEnabled.HasValue && !this.IsEnabled.Value) dictPropertyList.Add("disabled", "true"); if (this.IsShow.HasValue && !this.IsShow.Value) { if (dictPropertyList.Keys.Contains("style")) dictPropertyList["style"] += "display:none;"; else dictPropertyList.Add("style", "display:none;"); } if (this.Width.HasValue && this.Width > 0) { string widthString = string.Format("width:{0};", (Width > 1 ? (Width.ToString() + "px") : ((Width * 100).ToString() + "%"))); if (dictPropertyList.Keys.Contains("style")) dictPropertyList["style"] += widthString; else dictPropertyList.Add("style", widthString); } if (this.Height.HasValue && this.Height > 0) { string heightString = string.Format("height:{0};", (Height > 1 ? (Height.ToString() + "px") : ((Height * 100).ToString() + "%"))); if (dictPropertyList.Keys.Contains("style")) dictPropertyList["style"] += heightString; else dictPropertyList.Add("style", heightString); } return dictPropertyList; } public static BaseControl CreateControl(RichTextOptions richTextOptions, IDictionary attributes = null) { RichText txtBox = new RichText(); txtBox.CssClass = richTextOptions.CssClass; txtBox.ID = richTextOptions.ID ?? "txt_" + Guid.NewGuid().ToString().Substring(0, 6); txtBox.Name = richTextOptions.Name; txtBox.Title = richTextOptions.Title; txtBox.Value = richTextOptions.Value; txtBox.IsEnabled = richTextOptions.IsEnabled; txtBox.IsShow = richTextOptions.IsShow; txtBox.IsRequired = richTextOptions.IsRequired; txtBox.Validator = richTextOptions.Validator; txtBox.Width = richTextOptions.Width; txtBox.Height = richTextOptions.Height; if (attributes != null) { txtBox.Attributes = attributes; } return txtBox; } } }