当前位置: 首页>>代码示例>>C#>>正文


C# HtmlHelper.Encode方法代码示例

本文整理汇总了C#中System.Web.Mvc.HtmlHelper.Encode方法的典型用法代码示例。如果您正苦于以下问题:C# HtmlHelper.Encode方法的具体用法?C# HtmlHelper.Encode怎么用?C# HtmlHelper.Encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Mvc.HtmlHelper的用法示例。


在下文中一共展示了HtmlHelper.Encode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: PreviewBox

        private static IHtmlString PreviewBox(HtmlHelper html, string url, string title, int width, int height, string frameCssClass)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<div class=\"bcms-preview-box\">");
            sb.AppendFormat("<iframe class=\"{0}\" width=\"{1}\" height=\"{2}\" scrolling=\"no\" border=\"0\" frameborder=\"0\" src=\"{3}\" />", frameCssClass, width, height, html.Encode(url));
            sb.AppendLine();
            sb.AppendFormat("<div class=\"bcms-zoom-overlay\" data-preview-title=\"{0}\" data-preview-url=\"{1}\"> </div>", html.Encode(title), html.Encode(url));
            sb.AppendLine();
            sb.AppendLine("</div>");

            return new MvcHtmlString(sb.ToString());
        }
开发者ID:pmaciulis,项目名称:BetterCMS,代码行数:13,代码来源:PreviewHelper.cs

示例2: LoopBranch

        private static void LoopBranch(SiteMapNodeCollection nodeCollection, ref StringBuilder sb, ref HtmlHelper helper, bool isSub, string[] userroles)
        {
            string newUrl = HttpRuntime.AppDomainAppVirtualPath.TrimEnd('/');

            string menuclass = "cssMenui0";
            if (isSub) menuclass = "cssMenui";
            foreach (SiteMapNode node in nodeCollection)
            {
                bool nodeDisplayStatus = false;
                foreach (var role in node.Roles)
                {
                    if (role.Equals("*") || userroles.Contains(role))
                    {
                        nodeDisplayStatus = true;
                        break;
                    }
                }

                if (nodeDisplayStatus)
                {

                    sb.AppendLine("<li class=\"" + menuclass + "\">");

                    //if (SiteMap.CurrentNode == node)
                    //{
                    //    if (node.ChildNodes.Count > 0)
                    //        sb.AppendFormat("<a class=\"cssMenui0\" href='{0}'>{1}</a>", node.Url, helper.Encode(node.Title));
                    //    else
                    //        sb.AppendFormat("<a class=\"cssMenui0\" href='{0}'>{1}</a>", node.Url, helper.Encode(node.Title));
                    //}
                    //else
                    //{
                    newUrl += node.Url;
                        if (node.ChildNodes.Count > 0)
                            sb.AppendFormat("<a class=\"" + menuclass + "\" href='{0}'><span>{1}</span><![if gt IE 6]></a><![endif]><!--[if lte IE 6]><table><tr><td><![endif]-->", newUrl, helper.Encode(node.Title));
                        else
                            sb.AppendFormat("<a class=\"" + menuclass + "\" href='{0}'>{1}</a>", newUrl, helper.Encode(node.Title));

                    //}

                    if (node.ChildNodes.Count > 0)
                    {
                        sb.Append("<ul class=\"cssMenum\">");
                        LoopBranch(node.ChildNodes, ref sb, ref helper, true, userroles);
                        sb.Append("</ul>");
                    }
                    sb.AppendLine("<!--[if lte IE 6]></td></tr></table></a><![endif]--></li>");
                }
            }
        }
开发者ID:paulallies,项目名称:NMPIB,代码行数:50,代码来源:PureCssMenu.cs

示例3: LoopBranch

        private static void LoopBranch(SiteMapNodeCollection nodeCollection, ref StringBuilder sb, ref HtmlHelper helper)
        {
            IRoleRepository db = new RoleRepository();
            string User_CAI = HttpContext.Current.User.Identity.Name.ToUpper().Replace("CT\\","");
            string User_Role = db.GetUserRolesByUser(User_CAI);
            foreach (SiteMapNode node in nodeCollection)
            {
                string newUrl = HttpRuntime.AppDomainAppVirtualPath.TrimEnd('/');
                bool nodeDisplayStatus = false;
                foreach (var role in node.Roles)
                {
                    if (role.Equals("*") || role.Equals(User_Role))
                    {
                        nodeDisplayStatus = true;
                        break;
                    }
                }

                if (nodeDisplayStatus)
                {
                    sb.AppendLine("<li>");

                    if (SiteMap.CurrentNode == node)
                    {
                        newUrl += node.Url;
                        if (node.ChildNodes.Count > 0)
                            sb.AppendFormat("<a class='selectedMenuItem' href='{0}'>{1}</a>", newUrl, helper.Encode(node.Title));
                        else
                            sb.AppendFormat("<a class='selectedMenuItem' href='{0}'>{1}</a>", newUrl, helper.Encode(node.Title));
                    }
                    else
                    {
                        newUrl += node.Url;
                        if (node.ChildNodes.Count > 0)
                            sb.AppendFormat("<a href='{0}'>{1}</a>", newUrl, helper.Encode(node.Title));
                        else
                            sb.AppendFormat("<a href='{0}'>{1}</a>", newUrl, helper.Encode(node.Title));

                    }

                    if (node.ChildNodes.Count > 0)
                    {
                        sb.Append("<ul>");
                        LoopBranch(node.ChildNodes, ref sb, ref helper);
                        sb.Append("</ul>");
                    }
                    sb.AppendLine("</li>");
                }
            }
        }
开发者ID:paulallies,项目名称:tsdt,代码行数:50,代码来源:MenuHelper.cs

示例4: WriteInput

        public override MvcHtmlString WriteInput(HtmlHelper helper, object htmlAttributes)
        {
            TagBuilder tb = new TagBuilder("div");
            IDictionary<string, object> efHtmlAttributes = new RouteValueDictionary(htmlAttributes);
            AddCommonHtmlAttributes(efHtmlAttributes);
            foreach (var kvp in efHtmlAttributes)
            {
                KeyValuePair<string, string> kvpToAdd = new KeyValuePair<string, string>(kvp.Key, Convert.ToString(kvp.Value));
                tb.Attributes.Add(kvpToAdd);
            }
            tb.Attributes.Add("id", InputName);
            tb.Attributes.Add("style", string.Format("position:relative; width: {0}; height: {1}", EditorWidth ?? "500px", EditorHeight ?? "200px"));

            tb.InnerHtml = helper.Encode(this.Value);

            string scriptFormat =
                @"<script>
                    $(function() {{
                        var editor = ace.edit({0});
                        editor.setTheme('ace/theme/monokai');
                        editor.getSession().setMode('ace/mode/xml');
                    }});
                </script>";
            //string script = string.Format(scriptFormat, InputName);
            string script = string.Format(scriptFormat, getJavascriptString(helper, InputName));

            return new MvcHtmlString(tb.ToString() + script);
        }
开发者ID:rupeshtelang,项目名称:ExpressForms,代码行数:28,代码来源:ExpressFormsAceInput.cs

示例5: RenderElementByType

        private static String RenderElementByType(HtmlHelper html, FormElement model, String elementName, String elementValue)
        {
            var builder = new StringBuilder();
            switch (model.Type)
            {
                case FormElementType.TextField:
                    {
                        builder.Append(html.Encode(model.Title));
                        break;
                    }
                case FormElementType.TextBox:
                    {
                        builder.Append(html.Label(elementName, model.Title));
                        builder.Append("<br/>");
                        builder.Append(html.TextBox(elementName, elementValue));
                        break;
                    }
                case FormElementType.TextArea:
                    {
                        builder.Append(html.Label(elementName, model.Title));
                        builder.Append("<br/>");
                        builder.Append(html.TextArea(elementName, elementValue));
                        break;
                    }
                case FormElementType.CheckBox:
                    {
                        builder.Append(html.SimpleCheckBox(elementName, FormCollectionExtensions.BooleanValue(elementValue)));
                        builder.Append(html.Label(elementName, model.Title));
                        break;
                    }
                case FormElementType.DropDownList:
                    {
                        builder.Append(html.Label(elementName, model.Title));
                        builder.Append("<br/>");
                        builder.Append(html.DropDownList(elementName, ParseElementValuesForDropDown(model.ElementValues, elementValue)));
                        break;
                    }
                case FormElementType.RadioButtons:
                    {
                        builder.Append(html.Label(elementName, model.Title));
                        builder.Append("<br/>");
                        builder.Append(html.RadioList(elementName, ParseElementValuesForRadioButtons(model.ElementValues, elementName), elementValue));
                        break;
                    }
                case FormElementType.Captcha:
                    {
                        builder.Append(html.CaptchaImage(CaptchaDefaultHeight, CaptchaDefaultWidth));
                        builder.Append(html.Label(elementName, String.Empty));
                        builder.Append("<br/>");
                        builder.Append(html.CaptchaTextBox(elementName));
                        break;
                    }

                default:
                    break;
            }

            return builder.ToString();
        }
开发者ID:coreframework,项目名称:Core-Framework,代码行数:59,代码来源:FormElementsExtensions.cs

示例6: InputLabel

 public void InputLabel(HtmlHelper Html, TextWriter Output, dynamic Shape, string For, object Title) {
     if (Title != null) {
         var label = _tagBuilderFactory.Create(Shape, "label");
         label.MergeAttribute("for", For);
         label.InnerHtml = Html.Encode(Title);
         Output.WriteLine(label.ToString());
     }
 }
开发者ID:kerrjon,项目名称:MNFathers,代码行数:8,代码来源:EditorShapes.cs

示例7: InputRequiredMarker

 public void InputRequiredMarker(TextWriter Output, HtmlHelper Html, dynamic Shape, object ErrorMessage, bool? IsValid) {
     if (!IsValid.GetValueOrDefault(true) && ErrorMessage != null) {
         var span = _tagBuilderFactory.Create(Shape, "span");
         span.AddCssClass(HtmlHelper.ValidationMessageCssClassName);
         span.InnerHtml = Html.Encode(Shape.ErrorMessage);
         Output.WriteLine(span.ToString());
     }
 }
开发者ID:kerrjon,项目名称:MNFathers,代码行数:8,代码来源:EditorShapes.cs

示例8: PreviewBox

        private static IHtmlString PreviewBox(HtmlHelper html, string previewUrl, string openUrl, string title, string width, string height, string frameCssClass, bool asImage)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat(
                "<div class=\"bcms-grid-image-holder bcms-preview-zoom-box bcms-js-preview-box\" data-as-image=\"{0}\", data-preview-url=\"{1}\", data-title=\"{2}\", data-frame-css-class=\"{3}\", data-width=\"{4}\", data-height=\"{5}\">",
                asImage,
                html.Encode(previewUrl),
                html.Encode(title),
                frameCssClass,
                width,
                height);
            sb.AppendFormat("<div class=\"bcms-preview-zoom-overlay bcms-js-zoom-overlay\" data-preview-title=\"{0}\" data-preview-url=\"{1}\"> </div>", html.Encode(title), html.Encode(openUrl));
            sb.AppendLine();
            sb.AppendLine("</div>");

            return new MvcHtmlString(sb.ToString());
        }
开发者ID:juancarlospalomo,项目名称:tantumcms,代码行数:18,代码来源:PreviewHelper.cs

示例9: RenderCheckboxLabelHtml

        public static string RenderCheckboxLabelHtml(HtmlHelper htmlHelper, string expression, string labelText, string checkBoxHtml, IDictionary<string, object> htmlAttributes = null)
        {
            var divBuilder = new TagBuilder("div")
            {
                InnerHtml = RenderLabel(htmlHelper, expression, String.Concat(checkBoxHtml, " ", htmlHelper.Encode(labelText)), htmlAttributes).ToHtmlStringSafe()
            };

            divBuilder.AddCssClass("checkbox");

            return divBuilder.ToString(TagRenderMode.Normal);
        }
开发者ID:isannn,项目名称:Build.Mvc,代码行数:11,代码来源:LabelHelper.cs

示例10: PreviewBox

        private static IHtmlString PreviewBox(HtmlHelper html, string url, string title, string width, string height, string frameCssClass, bool asImage)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("<div class=\"bcms-preview-box\">");
            if (asImage)
            {
                sb.AppendFormat("<img src=\"{0}\" alt=\"{1}\" />", html.Encode(url), html.Encode(title));
            }
            else
            {
                sb.AppendFormat("<iframe class=\"{0}\" width=\"{1}\" height=\"{2}\" scrolling=\"no\" border=\"0\" frameborder=\"0\" src=\"{3}\" style=\"background-color:white;\"/>", frameCssClass, width, height, html.Encode(url));
            }
            sb.AppendLine();
            sb.AppendFormat("<div class=\"bcms-zoom-overlay\" data-preview-title=\"{0}\" data-preview-url=\"{1}\"> </div>", html.Encode(title), html.Encode(url));
            sb.AppendLine();
            sb.AppendLine("</div>");

            return new MvcHtmlString(sb.ToString());
        }
开发者ID:tkirda,项目名称:BetterCMS,代码行数:20,代码来源:PreviewHelper.cs

示例11: LabelHelper

 /// <summary>
 /// Creates the label HTML.
 /// </summary>
 public static MvcHtmlString LabelHelper(HtmlHelper html,
                                         ModelMetadata metadata,
                                         string htmlFieldName,
                                         string labelText,
                                         IDictionary<string, object> htmlAttributes)
 {
     string str = labelText ?? (metadata.DisplayName ?? (metadata.PropertyName ?? htmlFieldName.Split(new[] {'.'}).Last()));
     if ( String.IsNullOrEmpty(str) )
     {
         return MvcHtmlString.Empty;
     }
     var tagBuilder = new TagBuilder("label") {InnerHtml = html.Encode(str)};
     tagBuilder.Attributes.Add("for", TagBuilder.CreateSanitizedId(html.ViewContext.ViewData.TemplateInfo.GetFullHtmlFieldName(htmlFieldName)));
     tagBuilder.MergeAttributes(htmlAttributes, true);
     return tagBuilder.ToMvcHtmlString(TagRenderMode.Normal);
 }
开发者ID:isannn,项目名称:Build.Mvc,代码行数:19,代码来源:BuildHelpers.cs

示例12: InputHint

 public void InputHint(dynamic Display, dynamic Shape, HtmlHelper Html, TextWriter Output, object Description/*, object ActionLinkValue, object ActionLink*/) {
     // <span class="hint">
     if (Description != null) {
         var span = _tagBuilderFactory.Create(Shape, "span");
         span.AddCssClass("hint");
         var html = Html.Encode(Description);
         html = html.Replace("\n", "</span><span class=\"hint\">");
         span.InnerHtml = html;
         Output.WriteLine(span.ToString(TagRenderMode.Normal));
     }
     // action link
     if (Shape.ActionLinkValue != null) {
         if (Shape.ActionLink is string) {
             Shape.ActionLink = new { Action = Shape.ActionLink };
         }
         Output.WriteLine("<p>" + Display.Link(RouteValues: Shape.ActionLink, Value: Shape.ActionLinkValue) + "</p>");
     }
 }
开发者ID:kerrjon,项目名称:MNFathers,代码行数:18,代码来源:EditorShapes.cs

示例13: Render

 /// <summary>
 /// Renders java script module resource initialization. 
 /// </summary>
 /// <param name="html">Html helper.</param>
 public void Render(HtmlHelper html)
 {
     try
     {
         var resourceObject = resource();
         if (resourceObject != null)
         {
             string globalization = string.Format("{0}.globalization.{1} = '{2}';", javaScriptModule.FriendlyName, name, html.Encode(resourceObject));
             html.ViewContext.Writer.WriteLine(globalization);
         }
         else
         {
             Log.WarnFormat("Resource object not found to globalize {0}.{1} from resource {2}.", javaScriptModule, name, resource);
         }
     }
     catch (Exception ex)
     {
         Log.WarnFormat("Failed to render globalization for {0}.{1} from resource {2}.", ex, javaScriptModule, name, javaScriptModule);
     }
 }
开发者ID:pmaciulis,项目名称:BetterCMS,代码行数:24,代码来源:JavaScriptModuleGlobalization.cs

示例14: RenderReadOnly

        public static string RenderReadOnly(HtmlHelper html, BootstrapReadOnlyModel model, bool isPassword)
        {
            var combinedHtml = "{0}{1}{2}";

            model.htmlAttributes.MergeHtmlAttributes(html.GetUnobtrusiveValidationAttributes(model.htmlFieldName, model.metadata));

            if (!string.IsNullOrEmpty(model.id)) model.htmlAttributes.Add("id", model.id);
            if (model.tooltipConfiguration != null) model.htmlAttributes.MergeHtmlAttributes(model.tooltipConfiguration.ToDictionary());
            if (model.tooltip != null) model.htmlAttributes.MergeHtmlAttributes(model.tooltip.ToDictionary());
            // assign placeholder class
            if (!string.IsNullOrEmpty(model.placeholder)) model.htmlAttributes.Add("placeholder", model.placeholder);
            // build html for input

            string input = html.Hidden(model.htmlFieldName, model.value).ToHtmlString();

            if (model.value != null && model.value.GetType().IsEnum)
            {
                input =  input + ((Enum)model.value).GetEnumDescription();
            }
            else
            {
                input = input + html.Encode(model.value);

            }

            // account for appendString, prependString, and AppendButtons
            if (!string.IsNullOrEmpty(model.prependString) ||
                !string.IsNullOrEmpty(model.appendString) ||
                model.prependButtons.Any() ||
                model.appendButtons.Any() ||
                model.iconPrepend != Icons._not_set ||
                model.iconAppend != Icons._not_set ||
                !string.IsNullOrEmpty(model.iconPrependCustomClass) ||
                !string.IsNullOrEmpty(model.iconAppendCustomClass))
            {
                var appendPrependContainer = new TagBuilder("div");
                var addOnPrependString = "";
                var addOnAppendString = "";
                var addOnPrependButtons = "";
                var addOnAppendButtons = "";
                var addOnPrependIcon = "";
                var addOnAppendIcon = "";

                var addOn = new TagBuilder("span");
                addOn.AddCssClass("add-on");
                if (!string.IsNullOrEmpty(model.prependString))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    addOn.InnerHtml = model.prependString;
                    addOnPrependString = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.appendString))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    addOn.InnerHtml = model.appendString;
                    addOnAppendString = addOn.ToString();
                }
                if (model.prependButtons.Count > 0)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    model.prependButtons.ForEach(x => addOnPrependButtons += x.ToHtmlString());
                }
                if (model.appendButtons.Count > 0)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    model.appendButtons.ForEach(x => addOnAppendButtons += x.ToHtmlString());
                }
                if (model.iconPrepend != Icons._not_set)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    addOn.InnerHtml = new BootstrapIcon(model.iconPrepend, model.iconPrependIsWhite).ToHtmlString();
                    addOnPrependIcon = addOn.ToString();
                }
                if (model.iconAppend != Icons._not_set)
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    addOn.InnerHtml = new BootstrapIcon(model.iconAppend, model.iconAppendIsWhite).ToHtmlString();
                    addOnAppendIcon = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.iconPrependCustomClass))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-prepend");
                    var i = new TagBuilder("i");
                    i.AddCssClass(model.iconPrependCustomClass);
                    addOn.InnerHtml = i.ToString(TagRenderMode.Normal);
                    addOnPrependIcon = addOn.ToString();
                }
                if (!string.IsNullOrEmpty(model.iconAppendCustomClass))
                {
                    appendPrependContainer.AddOrMergeCssClass("input-append");
                    var i = new TagBuilder("i");
                    i.AddCssClass(model.iconAppendCustomClass);
                    addOn.InnerHtml = i.ToString(TagRenderMode.Normal);
                    addOnAppendIcon = addOn.ToString();
                }

                appendPrependContainer.InnerHtml = addOnPrependButtons + addOnPrependIcon + addOnPrependString + "{0}" + addOnAppendString + addOnAppendIcon + addOnAppendButtons;
                combinedHtml = appendPrependContainer.ToString(TagRenderMode.Normal) + "{1}{2}";
            }

//.........这里部分代码省略.........
开发者ID:ngadotnet,项目名称:TwitterBootstrapMvc,代码行数:101,代码来源:Renderer.ReadOnly.cs

示例15: Pager_Gap

        public IHtmlString Pager_Gap(HtmlHelper Html, dynamic Display, object Value) {
            var tagBuilder = new TagBuilder("span");
            tagBuilder.InnerHtml = Html.Encode(Value is string ? (string)Value : Display(Value));

            return MvcHtmlString.Create(tagBuilder.ToString());
        }
开发者ID:NickAndersonX,项目名称:xodb,代码行数:6,代码来源:CoreShapes.cs


注:本文中的System.Web.Mvc.HtmlHelper.Encode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。