public static IHtmlContent Replace(this IHtmlContent value, IHtmlHelper htmlHelper, string findExpression, IHtmlContent replacementHtmlContent) { var originalString = value.GetString(); var replacementString = replacementHtmlContent.GetString(); var stringReplacedHtmlContent = originalString.Replace(findExpression, replacementString); return(htmlHelper.Raw(stringReplacedHtmlContent)); }
public static IHtmlContent Base64Encode(this IHtmlHelper htmlHelper, IHtmlContent parameter, Encoding encoding) { var originalString = parameter.GetString(); return(htmlHelper .Raw(Convert .ToBase64String(encoding .GetBytes(originalString)))); }
/// <summary> /// Returns display tag of a value truncated by the given length and use bootstrap pop-over to display the complete value /// </summary> /// <param name="expression">Lambda expression for the property</param> /// <param name="textMaxLength">Maximum length of the displayed text</param> /// <param name="popOverTitle">The pop-over title text</param> /// <param name="seeMoreHtml">html text for see more if the text is truncated</param> /// <param name="showAllContentInPopover">True if you want to show the complete value in the pop-over. False to display the rest of the value only</param> /// <returns>HtmlString</returns> public static HtmlContentBuilder DisplayWithTruncateFor <TModel, TProperty>( this IHtmlHelper <TModel> helper, Expression <Func <TModel, TProperty> > expression, int textMaxLength = 50, string popOverTitle = "", string seeMoreHtml = " المزيد >>", bool showAllContentInPopover = false, TruncateMethod method = TruncateMethod.Popover) { var expresionProvider = helper.ViewContext.HttpContext.RequestServices .GetService(typeof(ModelExpressionProvider)) as ModelExpressionProvider; string name = helper.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(expresionProvider.GetExpressionText(expression)); IHtmlContent value = helper.DisplayFor(expression); HtmlContentBuilder result = helper.DisplayWithTruncate(name, value.GetString(), textMaxLength, popOverTitle, seeMoreHtml, showAllContentInPopover, method); return(result); }
/// <summary>输出字符串</summary> /// <param name="Html"></param> /// <param name="name"></param> /// <param name="value"></param> /// <param name="length"></param> /// <param name="htmlAttributes"></param> /// <returns></returns> public static IHtmlContent ForString(this IHtmlHelper Html, String name, String value, Int32 length = 0, Object htmlAttributes = null) { var atts = HtmlHelper.AnonymousObjectToHtmlAttributes(htmlAttributes); //if (!atts.ContainsKey("class")) atts.Add("class", "col-xs-10 col-sm-5"); //if (!atts.ContainsKey("class")) atts.Add("class", "col-xs-12 col-sm-8 col-md-6 col-lg-4"); if (!atts.ContainsKey("class")) { atts.Add("class", "form-control"); } // 首先输出图标 var ico = ""; IHtmlContent txt = null; if (name.EqualIgnoreCase("Pass", "Password")) { txt = Html.Password(name, value, atts); } else if (name.EqualIgnoreCase("Phone")) { ico = "<span class=\"input-group-addon\"><i class=\"glyphicon glyphicon-phone-alt\"></i></span>"; if (!atts.ContainsKey("type")) { atts.Add("type", "tel"); } txt = Html.TextBox(name, value, atts); } else if (name.EqualIgnoreCase("MobilePhone", "CellularPhone")) { ico = "<span class=\"input-group-addon\"><i class=\"glyphicon glyphicon-phone\"></i></span>"; if (!atts.ContainsKey("type")) { atts.Add("type", "tel"); } txt = Html.TextBox(name, value, atts); } else if (name.EqualIgnoreCase("email", "mail")) { ico = "<span class=\"input-group-addon\"><i class=\"glyphicon glyphicon-envelope\"></i></span>"; if (!atts.ContainsKey("type")) { atts.Add("type", "email"); } txt = Html.TextBox(name, value, atts); } else if (name.EndsWithIgnoreCase("url")) { ico = "<span class=\"input-group-addon\"><i class=\"glyphicon glyphicon-home\"></i></span>"; //if (!atts.ContainsKey("type")) atts.Add("type", "url"); txt = Html.TextBox(name, value, atts); } else if (length < 0 || length > 300) { txt = Html.TextArea(name, value, 3, 20, atts); } else { txt = Html.TextBox(name, value, atts); } var icog = "<div class=\"input-group\">{0}</div>"; var html = !String.IsNullOrWhiteSpace(ico) ? String.Format(icog, ico + txt.GetString()) : txt.GetString(); return(Html.Raw(html)); }