本文整理汇总了C#中IHtmlHelper.Encode方法的典型用法代码示例。如果您正苦于以下问题:C# IHtmlHelper.Encode方法的具体用法?C# IHtmlHelper.Encode怎么用?C# IHtmlHelper.Encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHtmlHelper
的用法示例。
在下文中一共展示了IHtmlHelper.Encode方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BooleanTemplateDropDownList
private static string BooleanTemplateDropDownList(IHtmlHelper htmlHelper, bool? value)
{
var selectTag = new TagBuilder("select", htmlHelper.HtmlEncoder);
selectTag.AddCssClass("list-box");
selectTag.AddCssClass("tri-state");
selectTag.Attributes["disabled"] = "disabled";
var builder = new StringBuilder();
builder.Append(selectTag.ToString(TagRenderMode.StartTag));
foreach (var item in TriStateValues(value))
{
var encodedText = htmlHelper.Encode(item.Text);
var option = DefaultHtmlGenerator.GenerateOption(item, encodedText, htmlHelper.HtmlEncoder);
builder.Append(option);
}
builder.Append(selectTag.ToString(TagRenderMode.EndTag));
return builder.ToString();
}
示例2: ObjectTemplate
public static string ObjectTemplate(IHtmlHelper htmlHelper)
{
var viewData = htmlHelper.ViewData;
var templateInfo = viewData.TemplateInfo;
var modelExplorer = viewData.ModelExplorer;
var builder = new StringBuilder();
if (modelExplorer.Model == null)
{
return modelExplorer.Metadata.NullDisplayText;
}
if (templateInfo.TemplateDepth > 1)
{
var text = modelExplorer.GetSimpleDisplayText();
if (modelExplorer.Metadata.HtmlEncode)
{
text = htmlHelper.Encode(text);
}
return text;
}
var serviceProvider = htmlHelper.ViewContext.HttpContext.RequestServices;
var viewEngine = serviceProvider.GetRequiredService<ICompositeViewEngine>();
foreach (var propertyExplorer in modelExplorer.Properties)
{
var propertyMetadata = propertyExplorer.Metadata;
if (!ShouldShow(propertyExplorer, templateInfo))
{
continue;
}
var divTag = new TagBuilder("div", htmlHelper.HtmlEncoder);
if (!propertyMetadata.HideSurroundingHtml)
{
var label = propertyMetadata.GetDisplayName();
if (!string.IsNullOrEmpty(label))
{
divTag.SetInnerText(label);
divTag.AddCssClass("display-label");
builder.AppendLine(divTag.ToString(TagRenderMode.Normal));
// Reset divTag for reuse.
divTag.Attributes.Clear();
}
divTag.AddCssClass("display-field");
builder.Append(divTag.ToString(TagRenderMode.StartTag));
}
var templateBuilder = new TemplateBuilder(
viewEngine,
htmlHelper.ViewContext,
htmlHelper.ViewData,
propertyExplorer,
htmlFieldName: propertyMetadata.PropertyName,
templateName: null,
readOnly: true,
additionalViewData: null);
builder.Append(templateBuilder.Build());
if (!propertyMetadata.HideSurroundingHtml)
{
builder.AppendLine(divTag.ToString(TagRenderMode.EndTag));
}
}
return builder.ToString();
}
示例3: StringTemplate
public static string StringTemplate(IHtmlHelper htmlHelper)
{
return htmlHelper.Encode(htmlHelper.ViewData.TemplateInfo.FormattedModelValue);
}
示例4: ObjectTemplate
public static IHtmlContent ObjectTemplate(IHtmlHelper htmlHelper)
{
var viewData = htmlHelper.ViewData;
var templateInfo = viewData.TemplateInfo;
var modelExplorer = viewData.ModelExplorer;
if (modelExplorer.Model == null)
{
return new HtmlString(modelExplorer.Metadata.NullDisplayText);
}
if (templateInfo.TemplateDepth > 1)
{
var text = modelExplorer.GetSimpleDisplayText();
if (modelExplorer.Metadata.HtmlEncode)
{
text = htmlHelper.Encode(text);
}
return new HtmlString(text);
}
var serviceProvider = htmlHelper.ViewContext.HttpContext.RequestServices;
var viewEngine = serviceProvider.GetRequiredService<ICompositeViewEngine>();
var content = new BufferedHtmlContent();
foreach (var propertyExplorer in modelExplorer.Properties)
{
var propertyMetadata = propertyExplorer.Metadata;
if (!ShouldShow(propertyExplorer, templateInfo))
{
continue;
}
var templateBuilder = new TemplateBuilder(
viewEngine,
htmlHelper.ViewContext,
htmlHelper.ViewData,
propertyExplorer,
htmlFieldName: propertyMetadata.PropertyName,
templateName: null,
readOnly: true,
additionalViewData: null);
var templateBuilderResult = templateBuilder.Build();
if (!propertyMetadata.HideSurroundingHtml)
{
var label = propertyMetadata.GetDisplayName();
if (!string.IsNullOrEmpty(label))
{
var labelTag = new TagBuilder("div");
labelTag.InnerHtml.SetContent(label);
labelTag.AddCssClass("display-label");
content.AppendLine(labelTag);
}
var valueDivTag = new TagBuilder("div");
valueDivTag.AddCssClass("display-field");
valueDivTag.InnerHtml.SetContent(templateBuilderResult);
content.AppendLine(valueDivTag);
}
else
{
content.Append(templateBuilderResult);
}
}
return content;
}