C# Class Sdl.Web.Mvc.Html.HtmlHelperExtensions

HtmlHelper extension methods for use in Views
Exibir arquivo Open project: sdl/dxa-web-application-dotnet

Public Methods

Method Description
Date ( this htmlHelper, System.DateTime date, string format = "D" ) : string

Format a date using the appropriate localization culture

DateDiff ( this htmlHelper, System.DateTime date, string format = "D" ) : string

Show a text representation of the difference between a given date and now

DxaEntities ( this htmlHelper, int containerSize ) : System.Web.Mvc.MvcHtmlString

Renders all Entities in the current Region Model.

This method will throw an exception if the current Model does not represent a Region.

DxaEntity ( this htmlHelper, EntityModel entity, int containerSize ) : System.Web.Mvc.MvcHtmlString

Renders a given Entity Model.

DxaEntity ( this htmlHelper, EntityModel entity, string viewName, int containerSize ) : System.Web.Mvc.MvcHtmlString

Renders a given Entity Model.

DxaEntityMarkup ( this htmlHelper ) : System.Web.Mvc.MvcHtmlString

Generates semantic markup (HTML/RDFa attributes) for the current Entity Model.

This method will throw an exception if the current Model does not represent an Entity.

DxaEntityMarkup ( this htmlHelper, EntityModel entity ) : System.Web.Mvc.MvcHtmlString

Generates semantic markup (HTML/RDFa attributes) for a given Entity Model.

DxaPageMarkup ( this htmlHelper ) : System.Web.Mvc.MvcHtmlString

Generates XPM markup for the current Page Model.

This method will throw an exception if the current Model does not represent a Page.

DxaPropertyMarkup ( this htmlHelper, EntityModel entity, string propertyName, int index ) : System.Web.Mvc.MvcHtmlString

Generates semantic markup (HTML/RDFa attributes) for a given property of a given Entity Model.

DxaPropertyMarkup ( this htmlHelper, Expression propertyExpression, int index ) : System.Web.Mvc.MvcHtmlString

Generates semantic markup (HTML/RDFa attributes) for a given property.

DxaPropertyMarkup ( this htmlHelper, string propertyName, int index ) : System.Web.Mvc.MvcHtmlString

Generates semantic markup (HTML/RDFa attributes) for a given property of the current Entity Model.

DxaRegion ( this htmlHelper ) : System.Web.Mvc.MvcHtmlString

Renders the current (Include) Page as a Region.

DxaRegion ( this htmlHelper, RegionModel region, int containerSize ) : System.Web.Mvc.MvcHtmlString

Renders a given Region Model

DxaRegion ( this htmlHelper, string regionName, string emptyViewName = null, int containerSize ) : System.Web.Mvc.MvcHtmlString

Renders a Region (of the current Page or Region Model) with a given name.

This method will throw an exception if the current Model does not represent a Page.

DxaRegionMarkup ( this htmlHelper ) : System.Web.Mvc.MvcHtmlString

Generates semantic markup (HTML/RDFa attributes) for the current Region Model.

This method will throw an exception if the current Model does not represent a Region.

DxaRegionMarkup ( this htmlHelper, RegionModel region ) : System.Web.Mvc.MvcHtmlString

Generates semantic markup (HTML/RDFa attributes) for a given Region Model.

DxaRegions ( this htmlHelper, string exclude = null, int containerSize ) : System.Web.Mvc.MvcHtmlString

Renders all Regions (of the current Page or Region Model), except the ones with given names.

This method will throw an exception if the current Model does not represent a Page.

DxaRichText ( this htmlHelper, Sdl.Web.Common.Models.RichText richText ) : System.Web.Mvc.MvcHtmlString

Renders a given RichText instance as HTML.

FormatResource ( this httpContext, string resourceName ) : object

Read a resource string and format it with parameters

FormatResource ( this htmlHelper, string resourceName ) : string

Read a resource string and format it with parameters

FriendlyFileSize ( this httpContext, long sizeInBytes ) : string

Convert a number into a filesize display value

Media ( this helper, MediaItem media, double aspect, string cssClass = null ) : System.Web.Mvc.MvcHtmlString
Media ( this helper, MediaItem media, string widthFactor, double aspect, string cssClass = null, int containerSize ) : System.Web.Mvc.MvcHtmlString

Write out a media item with a responsive url

Media ( this helper, MediaItem media, string widthFactor = null, string cssClass = null ) : System.Web.Mvc.MvcHtmlString
Resource ( this httpContext, string resourceName ) : object

Read a resource value

Resource ( this htmlHelper, string resourceName ) : string

Read a resource value

Private Methods

Method Description
Config ( this htmlHelper, string configName ) : string
Download ( this helper, MediaItem download ) : System.Web.Mvc.MvcHtmlString
GetRegions ( object model ) : RegionModelSet

Gets the Regions from a Page or Region Model.

GetResponsiveImageUrl ( string url ) : string
GetResponsiveImageUrl ( string url, double aspect, int containerSize ) : string
GetResponsiveImageUrl ( string url, string widthFactor, int containerSize ) : string
GetYouTubeEmbed ( string videoId, string cssClass = null ) : string
GetYouTubePlaceholder ( string videoId, string imageUrl, string altText = null, string cssClass = null, string elementName = "div", bool xmlCompliant = false ) : string
Image ( this helper, MediaItem image, string widthFactor, double aspect, string cssClass = null, int containerSize ) : System.Web.Mvc.MvcHtmlString
YouTubeVideo ( this helper, MediaItem video, string widthFactor, double aspect, string cssClass, int containerSize ) : System.Web.Mvc.MvcHtmlString

Method Details

Date() public static method

Format a date using the appropriate localization culture
public static Date ( this htmlHelper, System.DateTime date, string format = "D" ) : string
htmlHelper this HtmlHelper
date System.DateTime Date to format
format string Format string (default is "D")
return string

DateDiff() public static method

Show a text representation of the difference between a given date and now
public static DateDiff ( this htmlHelper, System.DateTime date, string format = "D" ) : string
htmlHelper this HtmlHelper
date System.DateTime The date to compare with the current date
format string Format string (default is "D")
return string

DxaEntities() public static method

Renders all Entities in the current Region Model.
This method will throw an exception if the current Model does not represent a Region.
public static DxaEntities ( this htmlHelper, int containerSize ) : System.Web.Mvc.MvcHtmlString
htmlHelper this The HtmlHelper instance on which the extension method operates.
containerSize int The size (in grid column units) of the containing element.
return System.Web.Mvc.MvcHtmlString

DxaEntity() public static method

Renders a given Entity Model.
public static DxaEntity ( this htmlHelper, EntityModel entity, int containerSize ) : System.Web.Mvc.MvcHtmlString
htmlHelper this The HtmlHelper instance on which the extension method operates.
entity Sdl.Web.Common.Models.EntityModel The Entity to render.
containerSize int The size (in grid column units) of the containing element.
return System.Web.Mvc.MvcHtmlString

DxaEntity() public static method

Renders a given Entity Model.
public static DxaEntity ( this htmlHelper, EntityModel entity, string viewName, int containerSize ) : System.Web.Mvc.MvcHtmlString
htmlHelper this The HtmlHelper instance on which the extension method operates.
entity Sdl.Web.Common.Models.EntityModel The Entity to render.
viewName string The (qualified) name of the View used to render the entity. This overrides the View set in .
containerSize int The size (in grid column units) of the containing element.
return System.Web.Mvc.MvcHtmlString

DxaEntityMarkup() public static method

Generates semantic markup (HTML/RDFa attributes) for the current Entity Model.
This method will throw an exception if the current Model does not represent an Entity.
public static DxaEntityMarkup ( this htmlHelper ) : System.Web.Mvc.MvcHtmlString
htmlHelper this The HtmlHelper instance on which the extension method operates.
return System.Web.Mvc.MvcHtmlString

DxaEntityMarkup() public static method

Generates semantic markup (HTML/RDFa attributes) for a given Entity Model.
public static DxaEntityMarkup ( this htmlHelper, EntityModel entity ) : System.Web.Mvc.MvcHtmlString
htmlHelper this The HtmlHelper instance on which the extension method operates.
entity Sdl.Web.Common.Models.EntityModel The Entity Model to generate semantic markup for.
return System.Web.Mvc.MvcHtmlString

DxaPageMarkup() public static method

Generates XPM markup for the current Page Model.
This method will throw an exception if the current Model does not represent a Page.
public static DxaPageMarkup ( this htmlHelper ) : System.Web.Mvc.MvcHtmlString
htmlHelper this The HtmlHelper instance on which the extension method operates.
return System.Web.Mvc.MvcHtmlString

DxaPropertyMarkup() public static method

Generates semantic markup (HTML/RDFa attributes) for a given property of a given Entity Model.
public static DxaPropertyMarkup ( this htmlHelper, EntityModel entity, string propertyName, int index ) : System.Web.Mvc.MvcHtmlString
htmlHelper this The HtmlHelper instance on which the extension method operates.
entity Sdl.Web.Common.Models.EntityModel The Entity Model.
propertyName string The name of the property.
index int The index of the property value (for multi-value properties).
return System.Web.Mvc.MvcHtmlString

DxaPropertyMarkup() public static method

Generates semantic markup (HTML/RDFa attributes) for a given property.
public static DxaPropertyMarkup ( this htmlHelper, Expression propertyExpression, int index ) : System.Web.Mvc.MvcHtmlString
htmlHelper this The HtmlHelper instance on which the extension method operates.
propertyExpression Expression A parameterless lambda expression which evaluates to a property of the current Entity Model.
index int The index of the property value (for multi-value properties).
return System.Web.Mvc.MvcHtmlString

DxaPropertyMarkup() public static method

Generates semantic markup (HTML/RDFa attributes) for a given property of the current Entity Model.
public static DxaPropertyMarkup ( this htmlHelper, string propertyName, int index ) : System.Web.Mvc.MvcHtmlString
htmlHelper this The HtmlHelper instance on which the extension method operates.
propertyName string The name of the property.
index int The index of the property value (for multi-value properties).
return System.Web.Mvc.MvcHtmlString

DxaRegion() public static method

Renders the current (Include) Page as a Region.
public static DxaRegion ( this htmlHelper ) : System.Web.Mvc.MvcHtmlString
htmlHelper this The HtmlHelper instance on which the extension method operates.
return System.Web.Mvc.MvcHtmlString

DxaRegion() public static method

Renders a given Region Model
public static DxaRegion ( this htmlHelper, RegionModel region, int containerSize ) : System.Web.Mvc.MvcHtmlString
htmlHelper this The HtmlHelper instance on which the extension method operates.
region Sdl.Web.Common.Models.RegionModel The Region Model to render. This object determines the View that will be used.
containerSize int The size (in grid column units) of the containing element.
return System.Web.Mvc.MvcHtmlString

DxaRegion() public static method

Renders a Region (of the current Page or Region Model) with a given name.
This method will throw an exception if the current Model does not represent a Page.
public static DxaRegion ( this htmlHelper, string regionName, string emptyViewName = null, int containerSize ) : System.Web.Mvc.MvcHtmlString
htmlHelper this The HtmlHelper instance on which the extension method operates.
regionName string The name of the Region to render. This object determines the View that will be used.
emptyViewName string /// The name of the View to use when no Region with the given name is found in the Page Model (i.e. no Entities exist in the given Region). /// If null (the default) then nothing will be rendered in that case. /// If the View is not in the Core Area, the View name has to be in the format AreaName:ViewName. ///
containerSize int The size (in grid column units) of the containing element.
return System.Web.Mvc.MvcHtmlString

DxaRegionMarkup() public static method

Generates semantic markup (HTML/RDFa attributes) for the current Region Model.
This method will throw an exception if the current Model does not represent a Region.
public static DxaRegionMarkup ( this htmlHelper ) : System.Web.Mvc.MvcHtmlString
htmlHelper this The HtmlHelper instance on which the extension method operates.
return System.Web.Mvc.MvcHtmlString

DxaRegionMarkup() public static method

Generates semantic markup (HTML/RDFa attributes) for a given Region Model.
public static DxaRegionMarkup ( this htmlHelper, RegionModel region ) : System.Web.Mvc.MvcHtmlString
htmlHelper this The HtmlHelper instance on which the extension method operates.
region Sdl.Web.Common.Models.RegionModel The Region Model to generate semantic markup for.
return System.Web.Mvc.MvcHtmlString

DxaRegions() public static method

Renders all Regions (of the current Page or Region Model), except the ones with given names.
This method will throw an exception if the current Model does not represent a Page.
public static DxaRegions ( this htmlHelper, string exclude = null, int containerSize ) : System.Web.Mvc.MvcHtmlString
htmlHelper this The HtmlHelper instance on which the extension method operates.
exclude string The (comma separated) name(s) of the Regions to exclude. Can be null (the default) to render all Regions.
containerSize int The size (in grid column units) of the containing element.
return System.Web.Mvc.MvcHtmlString

DxaRichText() public static method

Renders a given RichText instance as HTML.
public static DxaRichText ( this htmlHelper, Sdl.Web.Common.Models.RichText richText ) : System.Web.Mvc.MvcHtmlString
htmlHelper this The HtmlHelper instance on which the extension method operates.
richText Sdl.Web.Common.Models.RichText The instance to render. If the rich text contains Entity Models, those will be rendered using applicable Views.
return System.Web.Mvc.MvcHtmlString

FormatResource() public static method

Read a resource string and format it with parameters
public static FormatResource ( this httpContext, string resourceName ) : object
httpContext this The HttpContext
resourceName string The resource key (eg core.readMoreText)
return object

FormatResource() public static method

Read a resource string and format it with parameters
public static FormatResource ( this htmlHelper, string resourceName ) : string
htmlHelper this HtmlHelper
resourceName string The resource key (eg core.readMoreText)
return string

FriendlyFileSize() public static method

Convert a number into a filesize display value
public static FriendlyFileSize ( this httpContext, long sizeInBytes ) : string
httpContext this The HttpContext
sizeInBytes long The file size in bytes
return string

Media() public static method

public static Media ( this helper, MediaItem media, double aspect, string cssClass = null ) : System.Web.Mvc.MvcHtmlString
helper this
media Sdl.Web.Common.Models.MediaItem
aspect double
cssClass string
return System.Web.Mvc.MvcHtmlString

Media() public static method

Write out a media item with a responsive url
public static Media ( this helper, MediaItem media, string widthFactor, double aspect, string cssClass = null, int containerSize ) : System.Web.Mvc.MvcHtmlString
helper this
media Sdl.Web.Common.Models.MediaItem The media item to write out
widthFactor string The factor to apply to the width - can be % (eg "100%") or absolute (eg "120")
aspect double The aspect ratio for the image
cssClass string Css class to apply to img tag
containerSize int The size (in grid column units) of the containing element
return System.Web.Mvc.MvcHtmlString

Media() public static method

public static Media ( this helper, MediaItem media, string widthFactor = null, string cssClass = null ) : System.Web.Mvc.MvcHtmlString
helper this
media Sdl.Web.Common.Models.MediaItem
widthFactor string
cssClass string
return System.Web.Mvc.MvcHtmlString

Resource() public static method

Read a resource value
public static Resource ( this httpContext, string resourceName ) : object
httpContext this The HttpContext
resourceName string The resource key (eg core.readMoreText)
return object

Resource() public static method

Read a resource value
public static Resource ( this htmlHelper, string resourceName ) : string
htmlHelper this HtmlHelper
resourceName string The resource key (eg core.readMoreText)
return string