Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more

Class PropertyRenderer

Property rendering in MVC.

Inheritance
System.Object
PropertyRenderer
Namespace: EPiServer.Web.Mvc.Html
Assembly: EPiServer.Cms.AspNetCore.HtmlHelpers.dll
Version: 12.0.3
Syntax
public class PropertyRenderer : Object

Constructors

PropertyRenderer()

Initializes a new instance of the PropertyRenderer class.

Declaration
public PropertyRenderer()

Properties

CustomSettingsAttributeWriter

Gets or sets the function to use to output custom settings attribute. Returned value is expected to be in format 'data-epi-property-customsetting=value'.

Declaration
public virtual Func<RouteValueDictionary, string, string> CustomSettingsAttributeWriter { get; set; }
Property Value
Type Description
System.Func<Microsoft.AspNetCore.Routing.RouteValueDictionary, System.String, System.String>

The custom settings attribute writer.

Methods

BeginEditSection(IHtmlHelper, String, String, String, Object)

Writes the required attribute to make an html element editable (when in edit mode).

BeginEditSection/EndEditSection should be used instead of EditAttributes when rendering a block or inside partial views for blocks.

The difference between EditAttributes and BeginEditSection/EndEditSection is that when using BeginEditSection then no other edit hints for nested properties will be written out before EndEditSection is called.

Declaration
public virtual IHtmlContent BeginEditSection(IHtmlHelper helper, string htmlElement, string propertyKey, string propertyName, object htmlAttributes)
Parameters
Type Name Description
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper helper

The html helper.

System.String htmlElement

The HTML element.

System.String propertyKey

PageEditing.DataEPiPropertyName

System.String propertyName

The property name.

System.Object htmlAttributes

An anonymous object with additional HTML attributes.

Returns
Type Description
Microsoft.AspNetCore.Html.IHtmlContent

The required attribute to make an html element editable.

Remarks

This should be used together with EndEditSection.

CreateEditElement(IHtmlHelper, String, String, String, String, Func<String>, Func<String>, TextWriter)

Creates an edit container. The object can create an element in edit mode

Declaration
public virtual EditContainer CreateEditElement(IHtmlHelper helper, string epiPropertyKey, string epiPropertyName, string editElementName, string editElementCssClass, Func<string> renderSettingsAttributeWriter, Func<string> editorSettingsAttributeWriter, TextWriter writer)
Parameters
Type Name Description
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper helper

The html helper.

System.String epiPropertyKey

Key of the epi property.

System.String epiPropertyName

Name of the epi property.

System.String editElementName

Name of the edit element.

System.String editElementCssClass

The CSS class for edit element.

System.Func<System.String> renderSettingsAttributeWriter

The render settins attribute writer action.

System.Func<System.String> editorSettingsAttributeWriter

The editor settins attribute writer action.

System.IO.TextWriter writer

The writer.

Returns
Type Description
EditContainer

EditContainer object. At dispose, the element end will be written.

CurrentContentContainsProperty<TModel>(IHtmlHelper<TModel>, String)

Indicates if a property with the propertyName exists on the current content.

Declaration
protected virtual bool CurrentContentContainsProperty<TModel>(IHtmlHelper<TModel> html, string propertyName)
Parameters
Type Name Description
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel> html

The HTML helper instance that this method extends.

System.String propertyName

The property name.

Returns
Type Description
System.Boolean

True if the current content contains a property with the property name.

Type Parameters
Name Description
TModel

The content type

EditAttributes(IHtmlHelper, String, String)

Get the required attribute to make an html element editable. Will return an empty string if not in edit context mode.

Declaration
public virtual IHtmlContent EditAttributes(IHtmlHelper helper, string propertyKey, string propertyName)
Parameters
Type Name Description
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper helper

The html helper.

System.String propertyKey

The property key.

System.String propertyName

The property name.

Returns
Type Description
Microsoft.AspNetCore.Html.IHtmlContent

The required attribute to make an html element editable.

EndEditSection(IHtmlHelper, String)

Marks that the corresponding BeginEditSection is ended.

BeginEditSection/EndEditSection should be used instead of EditAttributes when rendering a block or inside partial views for blocks.

The difference between EditAttributes and BeginEditSection is that when using BeginEditSection then no other edit hints for nested properties will be written out before EndEditSection is called.

Declaration
public static IHtmlContent EndEditSection(IHtmlHelper helper, string htmlElement)
Parameters
Type Name Description
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper helper

The html helper.

System.String htmlElement

The HTML element.

Returns
Type Description
Microsoft.AspNetCore.Html.IHtmlContent

the end element.

Remarks

This should be used together with BeginEditSection and outputs the end element.

GetHtmlForDefaultMode<TModel, TValue>(String, String, String, String, Func<String, IHtmlContent>)

Returns HTML markup for the property when it's rendered in default mode.

Declaration
protected virtual IHtmlContent GetHtmlForDefaultMode<TModel, TValue>(string propertyName, string templateName, string elementName, string elementCssClass, Func<string, IHtmlContent> displayForAction)
Parameters
Type Name Description
System.String propertyName

The property name.

System.String templateName

The name of the template that should be called.

System.String elementName

The surrounded element name.

System.String elementCssClass

The css class element name.

System.Func<System.String, Microsoft.AspNetCore.Html.IHtmlContent> displayForAction

The displayFor action.

Returns
Type Description
Microsoft.AspNetCore.Html.IHtmlContent
Type Parameters
Name Description
TModel

The content data type.

TValue

The type of the value.

GetHtmlForEditMode<TModel, TValue>(IHtmlHelper<TModel>, String, Object, Func<String, IHtmlContent>, String, String, String, RouteValueDictionary)

Returns HTML markup for each property in the object that is represented by the Expression expression.

Declaration
protected virtual IHtmlContent GetHtmlForEditMode<TModel, TValue>(IHtmlHelper<TModel> html, string viewModelPropertyName, object editorSettings, Func<string, IHtmlContent> displayForAction, string templateName, string editElementName, string editElementCssClass, RouteValueDictionary additionalValues)
Parameters
Type Name Description
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel> html

The HTML helper instance that this method extends.

System.String viewModelPropertyName

The property name.

System.Object editorSettings

Any custom editor settings.

System.Func<System.String, Microsoft.AspNetCore.Html.IHtmlContent> displayForAction

The The displayFor action.

System.String templateName

The name of the template that should be called.

System.String editElementName

The surrounded element name.

System.String editElementCssClass

The css class element name.

Microsoft.AspNetCore.Routing.RouteValueDictionary additionalValues

Additional values.

Returns
Type Description
Microsoft.AspNetCore.Html.IHtmlContent

The HTML markup for each property in the object that is represented by the expression.

Type Parameters
Name Description
TModel

The content data type.

TValue

The type of the value.

PropertyFor<TModel, TValue>(IHtmlHelper<TModel>, String, Object, Object, Expression<Func<TModel, TValue>>, Func<String, IHtmlContent>)

Returns HTML markup for each property in the object that is represented by the Expression expression.

Declaration
public virtual IHtmlContent PropertyFor<TModel, TValue>(IHtmlHelper<TModel> html, string viewModelPropertyName, object additionalViewData, object editorSettings, Expression<Func<TModel, TValue>> expression, Func<string, IHtmlContent> displayForAction)
Parameters
Type Name Description
Microsoft.AspNetCore.Mvc.Rendering.IHtmlHelper<TModel> html

The HTML helper instance that this method extends.

System.String viewModelPropertyName

The property name.

System.Object additionalViewData

An anonymous object that can contain additional view data that will be merged into the ViewDataDictionary instance that is created for the template.

System.Object editorSettings

Any custom editor settings.

System.Linq.Expressions.Expression<System.Func<TModel, TValue>> expression

An expression that identifies the object that contains the properties to display.

System.Func<System.String, Microsoft.AspNetCore.Html.IHtmlContent> displayForAction

The The displayFor action.

Returns
Type Description
Microsoft.AspNetCore.Html.IHtmlContent

The HTML markup for each property in the object that is represented by the expression.

Type Parameters
Name Description
TModel

The content data type.

TValue

The type of the value.

Extension Methods