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


C# HtmlHelper.Encode方法代码示例

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


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

示例1: UrlTemplate

 internal static string UrlTemplate(HtmlHelper html)
 {
     return String.Format(CultureInfo.InvariantCulture,
                          "<a href=\"{0}\">{1}</a>",
                          html.AttributeEncode(html.ViewContext.ViewData.Model),
                          html.Encode(html.ViewContext.ViewData.TemplateInfo.FormattedModelValue));
 }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:7,代码来源:DefaultDisplayTemplates.cs

示例2: ObjectTemplate

        internal static string ObjectTemplate(HtmlHelper html, TemplateHelpers.TemplateHelperDelegate templateHelper)
        {
            ViewDataDictionary viewData = html.ViewContext.ViewData;
            TemplateInfo templateInfo = viewData.TemplateInfo;
            ModelMetadata modelMetadata = viewData.ModelMetadata;
            StringBuilder builder = new StringBuilder();

            if (templateInfo.TemplateDepth > 1)
            {
                if (modelMetadata.Model == null)
                {
                    return modelMetadata.NullDisplayText;
                }

                // DDB #224751
                string text = modelMetadata.SimpleDisplayText;
                if (modelMetadata.HtmlEncode)
                {
                    text = html.Encode(text);
                }

                return text;
            }

            foreach (ModelMetadata propertyMetadata in modelMetadata.Properties.Where(pm => ShouldShow(pm, templateInfo)))
            {
                if (!propertyMetadata.HideSurroundingHtml)
                {
                    string label = LabelExtensions.LabelHelper(html, propertyMetadata, propertyMetadata.PropertyName).ToHtmlString();
                    if (!String.IsNullOrEmpty(label))
                    {
                        builder.AppendFormat(CultureInfo.InvariantCulture, "<div class=\"editor-label\">{0}</div>\r\n", label);
                    }

                    builder.Append("<div class=\"editor-field\">");
                }

                builder.Append(templateHelper(html, propertyMetadata, propertyMetadata.PropertyName, null /* templateName */, DataBoundControlMode.Edit, null /* additionalViewData */));

                if (!propertyMetadata.HideSurroundingHtml)
                {
                    builder.Append(" ");
                    builder.Append(html.ValidationMessage(propertyMetadata.PropertyName));
                    builder.Append("</div>\r\n");
                }
            }

            return builder.ToString();
        }
开发者ID:ahmetgoktas,项目名称:aspnetwebstack,代码行数:49,代码来源:DefaultEditorTemplates.cs

示例3: StringTemplate

 internal static string StringTemplate(HtmlHelper html)
 {
     return html.Encode(html.ViewContext.ViewData.TemplateInfo.FormattedModelValue);
 }
开发者ID:haoduotnt,项目名称:aspnetwebstack,代码行数:4,代码来源:DefaultDisplayTemplates.cs

示例4: UrlTemplate

        internal static string UrlTemplate(HtmlHelper html, object attributes = null)
        {
            var dataAttributes = html.ViewContext.ViewData.ModelMetadata.AdditionalValues.GetDataAttributes();
            var customAttributes = html.ViewContext.ViewData.ModelMetadata.AdditionalValues.GetCustomAttributes();
            dataAttributes.MergeAttributes(customAttributes);

            TagBuilder mailTo = new TagBuilder("a");
            mailTo.MergeAttribute("href", html.AttributeEncode(html.ViewContext.ViewData.Model));
            mailTo.MergeAttributes(dataAttributes);
            mailTo.InnerHtml = html.Encode(html.ViewContext.ViewData.TemplateInfo.FormattedModelValue);

            return mailTo.ToString(TagRenderMode.Normal);
        }
开发者ID:Gutek,项目名称:MVC-3-Html5EditorFor,代码行数:13,代码来源:Html5DefaultDisplayTemplates.cs


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