// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using System.Linq.Expressions; using Microsoft.AspNetCore.Html; namespace Microsoft.AspNetCore.Mvc.Rendering { /// /// Display-related extensions for and . /// public static class HtmlHelperDisplayExtensions { /// /// Returns HTML markup for the , using a display template. The template is found /// using the 's . /// /// The instance this method extends. /// /// Expression name, relative to the current model. May identify a single property or an /// that contains the properties to display. /// /// A new containing the created HTML. /// /// /// For example the default display template includes markup for each property in the /// 's value. /// /// /// Example s include string.Empty which identifies the current model and /// "prop" which identifies the current model's "prop" property. /// /// /// Custom templates are found under a DisplayTemplates folder. The folder name is case-sensitive on /// case-sensitive file systems. /// /// public static IHtmlContent Display(this IHtmlHelper htmlHelper, string expression) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.Display(expression, templateName: null, htmlFieldName: null, additionalViewData: null); } /// /// Returns HTML markup for the , using a display template and specified /// additional view data. The template is found using the 's /// . /// /// The instance this method extends. /// /// Expression name, relative to the current model. May identify a single property or an /// that contains the properties to display. /// /// /// An anonymous or /// that can contain additional view data that will be merged into the /// instance created for the template. /// /// A new containing the created HTML. /// /// /// For example the default display template includes markup for each property in the /// 's value. /// /// /// Example s include string.Empty which identifies the current model and /// "prop" which identifies the current model's "prop" property. /// /// /// Custom templates are found under a DisplayTemplates folder. The folder name is case-sensitive on /// case-sensitive file systems. /// /// public static IHtmlContent Display( this IHtmlHelper htmlHelper, string expression, object additionalViewData) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.Display( expression, templateName: null, htmlFieldName: null, additionalViewData: additionalViewData); } /// /// Returns HTML markup for the , using a display template. The template is found /// using the or the 's /// . /// /// The instance this method extends. /// /// Expression name, relative to the current model. May identify a single property or an /// that contains the properties to display. /// /// The name of the template used to create the HTML markup. /// A new containing the created HTML. /// /// /// For example the default display template includes markup for each property in the /// 's value. /// /// /// Example s include string.Empty which identifies the current model and /// "prop" which identifies the current model's "prop" property. /// /// /// Custom templates are found under a DisplayTemplates folder. The folder name is case-sensitive on /// case-sensitive file systems. /// /// public static IHtmlContent Display( this IHtmlHelper htmlHelper, string expression, string templateName) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.Display(expression, templateName, htmlFieldName: null, additionalViewData: null); } /// /// Returns HTML markup for the , using a display template and specified /// additional view data. The template is found using the or the /// 's . /// /// The instance this method extends. /// /// Expression name, relative to the current model. May identify a single property or an /// that contains the properties to display. /// /// The name of the template used to create the HTML markup. /// /// An anonymous or /// that can contain additional view data that will be merged into the /// instance created for the template. /// /// A new containing the created HTML. /// /// /// For example the default display template includes markup for each property in the /// 's value. /// /// /// Example s include string.Empty which identifies the current model and /// "prop" which identifies the current model's "prop" property. /// /// /// Custom templates are found under a DisplayTemplates folder. The folder name is case-sensitive on /// case-sensitive file systems. /// /// public static IHtmlContent Display( this IHtmlHelper htmlHelper, string expression, string templateName, object additionalViewData) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.Display( expression, templateName, htmlFieldName: null, additionalViewData: additionalViewData); } /// /// Returns HTML markup for the , using a display template and specified HTML /// field name. The template is found using the or the /// 's. /// /// The instance this method extends. /// /// Expression name, relative to the current model. May identify a single property or an /// that contains the properties to display. /// /// The name of the template used to create the HTML markup. /// /// A used to disambiguate the names of HTML elements that are created for /// properties that have the same name. /// /// A new containing the created HTML. /// /// /// For example the default display template includes markup for each property in the /// 's value. /// /// /// Example s include string.Empty which identifies the current model and /// "prop" which identifies the current model's "prop" property. /// /// /// Custom templates are found under a DisplayTemplates folder. The folder name is case-sensitive on /// case-sensitive file systems. /// /// public static IHtmlContent Display( this IHtmlHelper htmlHelper, string expression, string templateName, string htmlFieldName) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.Display(expression, templateName, htmlFieldName, additionalViewData: null); } /// /// Returns HTML markup for the , using a display template. The template is found /// using the 's . /// /// The instance this method extends. /// An expression to be evaluated against the current model. /// The type of the model. /// The type of the result. /// A new containing the created HTML. /// /// /// For example the default display template includes markup for each property in the /// result. /// /// /// Custom templates are found under a DisplayTemplates folder. The folder name is case-sensitive on /// case-sensitive file systems. /// /// public static IHtmlContent DisplayFor( this IHtmlHelper htmlHelper, Expression> expression) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (expression == null) { throw new ArgumentNullException(nameof(expression)); } return htmlHelper.DisplayFor( expression, templateName: null, htmlFieldName: null, additionalViewData: null); } /// /// Returns HTML markup for the , using a display template and specified /// additional view data. The template is found using the 's /// . /// /// The instance this method extends. /// An expression to be evaluated against the current model. /// /// An anonymous or /// that can contain additional view data that will be merged into the /// instance created for the template. /// /// The type of the model. /// The type of the result. /// A new containing the created HTML. /// /// /// For example the default display template includes markup for each property in the /// result. /// /// /// Custom templates are found under a DisplayTemplates folder. The folder name is case-sensitive on /// case-sensitive file systems. /// /// public static IHtmlContent DisplayFor( this IHtmlHelper htmlHelper, Expression> expression, object additionalViewData) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (expression == null) { throw new ArgumentNullException(nameof(expression)); } return htmlHelper.DisplayFor( expression, templateName: null, htmlFieldName: null, additionalViewData: additionalViewData); } /// /// Returns HTML markup for the , using a display template. The template is found /// using the or the 's /// . /// /// The instance this method extends. /// An expression to be evaluated against the current model. /// The name of the template used to create the HTML markup. /// The type of the model. /// The type of the result. /// A new containing the created HTML. /// /// /// For example the default display template includes markup for each property in the /// result. /// /// /// Custom templates are found under a DisplayTemplates folder. The folder name is case-sensitive on /// case-sensitive file systems. /// /// public static IHtmlContent DisplayFor( this IHtmlHelper htmlHelper, Expression> expression, string templateName) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (expression == null) { throw new ArgumentNullException(nameof(expression)); } return htmlHelper.DisplayFor( expression, templateName, htmlFieldName: null, additionalViewData: null); } /// /// Returns HTML markup for the , using a display template and specified /// additional view data. The template is found using the or the /// 's . /// /// The instance this method extends. /// An expression to be evaluated against the current model. /// The name of the template used to create the HTML markup. /// /// An anonymous or /// that can contain additional view data that will be merged into the /// instance created for the template. /// /// The type of the model. /// The type of the result. /// A new containing the created HTML. /// /// /// For example the default display template includes markup for each property in the /// result. /// /// /// Custom templates are found under a DisplayTemplates folder. The folder name is case-sensitive on /// case-sensitive file systems. /// /// public static IHtmlContent DisplayFor( this IHtmlHelper htmlHelper, Expression> expression, string templateName, object additionalViewData) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (expression == null) { throw new ArgumentNullException(nameof(expression)); } return htmlHelper.DisplayFor( expression, templateName, htmlFieldName: null, additionalViewData: additionalViewData); } /// /// Returns HTML markup for the , using a display template and specified HTML /// field name. The template is found using the or the /// 's . /// /// The instance this method extends. /// An expression to be evaluated against the current model. /// The name of the template used to create the HTML markup. /// /// A used to disambiguate the names of HTML elements that are created for properties /// that have the same name. /// /// The type of the model. /// The type of the result. /// A new containing the created HTML. /// /// /// For example the default display template includes markup for each property in the /// result. /// /// /// Custom templates are found under a DisplayTemplates folder. The folder name is case-sensitive on /// case-sensitive file systems. /// /// public static IHtmlContent DisplayFor( this IHtmlHelper htmlHelper, Expression> expression, string templateName, string htmlFieldName) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } if (expression == null) { throw new ArgumentNullException(nameof(expression)); } return htmlHelper.DisplayFor( expression, templateName: templateName, htmlFieldName: htmlFieldName, additionalViewData: null); } /// /// Returns HTML markup for the current model, using a display template. The template is found using the /// model's . /// /// The instance this method extends. /// A new containing the created HTML. /// /// /// For example the default display template includes markup for each property in the /// current model. /// /// /// Custom templates are found under a DisplayTemplates folder. The folder name is case-sensitive on /// case-sensitive file systems. /// /// public static IHtmlContent DisplayForModel(this IHtmlHelper htmlHelper) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.Display( expression: null, templateName: null, htmlFieldName: null, additionalViewData: null); } /// /// Returns HTML markup for the current model, using a display template and specified additional view data. The /// template is found using the model's . /// /// The instance this method extends. /// /// An anonymous or /// that can contain additional view data that will be merged into the /// instance created for the template. /// /// A new containing the created HTML. /// /// /// For example the default display template includes markup for each property in the /// current model. /// /// /// Custom templates are found under a DisplayTemplates folder. The folder name is case-sensitive on /// case-sensitive file systems. /// /// public static IHtmlContent DisplayForModel(this IHtmlHelper htmlHelper, object additionalViewData) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.Display( expression: null, templateName: null, htmlFieldName: null, additionalViewData: additionalViewData); } /// /// Returns HTML markup for the current model, using a display template. The template is found using the /// or the model's . /// /// The instance this method extends. /// The name of the template used to create the HTML markup. /// A new containing the created HTML. /// /// /// For example the default display template includes markup for each property in the /// current model. /// /// /// Custom templates are found under a DisplayTemplates folder. The folder name is case-sensitive on /// case-sensitive file systems. /// /// public static IHtmlContent DisplayForModel(this IHtmlHelper htmlHelper, string templateName) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.Display( expression: null, templateName: templateName, htmlFieldName: null, additionalViewData: null); } /// /// Returns HTML markup for the current model, using a display template and specified additional view data. The /// template is found using the or the model's /// . /// /// The instance this method extends. /// The name of the template used to create the HTML markup. /// /// An anonymous or /// that can contain additional view data that will be merged into the /// instance created for the template. /// /// A new containing the created HTML. /// /// /// For example the default display template includes markup for each property in the /// current model. /// /// /// Custom templates are found under a DisplayTemplates folder. The folder name is case-sensitive on /// case-sensitive file systems. /// /// public static IHtmlContent DisplayForModel( this IHtmlHelper htmlHelper, string templateName, object additionalViewData) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.Display( expression: null, templateName: templateName, htmlFieldName: null, additionalViewData: additionalViewData); } /// /// Returns HTML markup for the current model, using a display template and specified HTML field name. The /// template is found using the or the model's /// . /// /// The instance this method extends. /// The name of the template used to create the HTML markup. /// /// A used to disambiguate the names of HTML elements that are created for /// properties that have the same name. /// /// A new containing the created HTML. /// /// /// For example the default display template includes markup for each property in the /// current model. /// /// /// Custom templates are found under a DisplayTemplates folder. The folder name is case-sensitive on /// case-sensitive file systems. /// /// public static IHtmlContent DisplayForModel( this IHtmlHelper htmlHelper, string templateName, string htmlFieldName) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.Display( expression: null, templateName: templateName, htmlFieldName: htmlFieldName, additionalViewData: null); } /// /// Returns HTML markup for the current model, using a display template, specified HTML field name, and /// additional view data. The template is found using the or the model's /// . /// /// The instance this method extends. /// The name of the template used to create the HTML markup. /// /// A used to disambiguate the names of HTML elements that are created for /// properties that have the same name. /// /// /// An anonymous or /// that can contain additional view data that will be merged into the /// instance created for the template. /// /// A new containing the created HTML. /// /// /// For example the default display template includes markup for each property in the /// current model. /// /// /// Custom templates are found under a DisplayTemplates folder. The folder name is case-sensitive on /// case-sensitive file systems. /// /// public static IHtmlContent DisplayForModel( this IHtmlHelper htmlHelper, string templateName, string htmlFieldName, object additionalViewData) { if (htmlHelper == null) { throw new ArgumentNullException(nameof(htmlHelper)); } return htmlHelper.Display( expression: null, templateName: templateName, htmlFieldName: htmlFieldName, additionalViewData: additionalViewData); } } }