本文整理汇总了C#中IHtmlHelper.ValidationMessage方法的典型用法代码示例。如果您正苦于以下问题:C# IHtmlHelper.ValidationMessage方法的具体用法?C# IHtmlHelper.ValidationMessage怎么用?C# IHtmlHelper.ValidationMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHtmlHelper
的用法示例。
在下文中一共展示了IHtmlHelper.ValidationMessage方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ObjectTemplate
public static IHtmlContent ObjectTemplate(IHtmlHelper htmlHelper)
{
var viewData = htmlHelper.ViewData;
var templateInfo = viewData.TemplateInfo;
var modelExplorer = viewData.ModelExplorer;
if (templateInfo.TemplateDepth > 1)
{
if (modelExplorer.Model == null)
{
return new HtmlString(modelExplorer.Metadata.NullDisplayText);
}
var text = modelExplorer.GetSimpleDisplayText();
if (modelExplorer.Metadata.HtmlEncode)
{
return new StringHtmlContent(text);
}
return new HtmlString(text);
}
var serviceProvider = htmlHelper.ViewContext.HttpContext.RequestServices;
var viewEngine = serviceProvider.GetRequiredService<ICompositeViewEngine>();
var viewBufferScope = serviceProvider.GetRequiredService<IViewBufferScope>();
var content = new HtmlContentBuilder();
foreach (var propertyExplorer in modelExplorer.Properties)
{
var propertyMetadata = propertyExplorer.Metadata;
if (!ShouldShow(propertyExplorer, templateInfo))
{
continue;
}
var templateBuilder = new TemplateBuilder(
viewEngine,
viewBufferScope,
htmlHelper.ViewContext,
htmlHelper.ViewData,
propertyExplorer,
htmlFieldName: propertyMetadata.PropertyName,
templateName: null,
readOnly: false,
additionalViewData: null);
var templateBuilderResult = templateBuilder.Build();
if (!propertyMetadata.HideSurroundingHtml)
{
var label = htmlHelper.Label(propertyMetadata.PropertyName, labelText: null, htmlAttributes: null);
if (!string.IsNullOrEmpty(label.ToString()))
{
var labelTag = new TagBuilder("div");
labelTag.AddCssClass("editor-label");
labelTag.InnerHtml.SetContent(label);
content.AppendLine(labelTag);
}
var valueDivTag = new TagBuilder("div");
valueDivTag.AddCssClass("editor-field");
valueDivTag.InnerHtml.AppendHtml(templateBuilderResult);
valueDivTag.InnerHtml.AppendHtml(" ");
valueDivTag.InnerHtml.AppendHtml(htmlHelper.ValidationMessage(
propertyMetadata.PropertyName,
message: null,
htmlAttributes: null,
tag: null));
content.AppendLine(valueDivTag);
}
else
{
content.AppendHtml(templateBuilderResult);
}
}
return content;
}
示例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 (templateInfo.TemplateDepth > 1)
{
if (modelExplorer.Model == null)
{
return modelExplorer.Metadata.NullDisplayText;
}
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 = htmlHelper.Label(
propertyMetadata.PropertyName,
labelText: null,
htmlAttributes: null)
.ToString();
if (!string.IsNullOrEmpty(label))
{
divTag.AddCssClass("editor-label");
divTag.InnerHtml = label; // already escaped
builder.AppendLine(divTag.ToString(TagRenderMode.Normal));
// Reset divTag for reuse.
divTag.Attributes.Clear();
}
divTag.AddCssClass("editor-field");
builder.Append(divTag.ToString(TagRenderMode.StartTag));
}
var templateBuilder = new TemplateBuilder(
viewEngine,
htmlHelper.ViewContext,
htmlHelper.ViewData,
propertyExplorer,
htmlFieldName: propertyMetadata.PropertyName,
templateName: null,
readOnly: false,
additionalViewData: null);
builder.Append(templateBuilder.Build());
if (!propertyMetadata.HideSurroundingHtml)
{
builder.Append(" ");
builder.Append(htmlHelper.ValidationMessage(
propertyMetadata.PropertyName,
message: null,
htmlAttributes: null,
tag: null));
builder.AppendLine(divTag.ToString(TagRenderMode.EndTag));
}
}
return builder.ToString();
}