Class ImageHtmlHelper
HTML helper methods for rendering images.
Inherited Members
Namespace: AdaptiveImages.Rendering
Assembly: AdaptiveImages.dll
Syntax
public static class ImageHtmlHelper
Methods
RenderAdaptiveImage<TContent, TProperty>(IHtmlHelper<TContent>, Expression<Func<TContent, TProperty>>, int?, int?, int?, int?, int?, int?, bool, string?, string?, string?, bool, int?, int?, int?, IProportions?, IProportions?, IProportions?, IDimensions?, IDimensions?, IDimensions?)
Renders adaptive images based on size and proportions constraints, where applicable
Declaration
public static HtmlString RenderAdaptiveImage<TContent, TProperty>(this IHtmlHelper<TContent> html, Expression<Func<TContent, TProperty>> expression, int? largeBreakpoint = null, int? mediumBreakpoint = null, int? largeWidth = null, int? mediumWidth = null, int? smallWidth = null, int? maxWidth = null, bool ignoreConstraints = false, string? altText = null, string? cssClass = null, string? pictureCssClass = null, bool lazyLoad = false, int? largeQuality = null, int? mediumQuality = null, int? smallQuality = null, IProportions? largeCropToProportions = null, IProportions? mediumCropToProportions = null, IProportions? smallCropToProportions = null, IDimensions? largeCropToSize = null, IDimensions? mediumCropToSize = null, IDimensions? smallCropToSize = null) where TProperty : AdaptiveImage
Parameters
Type | Name | Description |
---|---|---|
IHtmlHelper<TContent> | html | Current HTML helper instance. |
Expression<Func<TContent, TProperty>> | expression | Expression targeting the AdaptiveImage property to render. |
int? | largeBreakpoint | Breakpoint for desktop. |
int? | mediumBreakpoint | Breakpoint for tablet. |
int? | largeWidth | Image width for desktop, if different from breakpoint. |
int? | mediumWidth | Image width for tablet, if different from breakpoint. |
int? | smallWidth | Image width for mobile, if different from breakpoint. |
int? | maxWidth | The maximum allowed rendering width if different from the default. |
bool | ignoreConstraints | Set to true to ignore any size or proportions constraints when rendering. |
string | altText | Alternate text to override any description set by the web editor. |
string | cssClass | CSS class to add to the img element. |
string | pictureCssClass | CSS class to add to the picture element. |
bool | lazyLoad | Whether images should be lazy loaded by the browser. |
int? | largeQuality | Compression quality for the large form factor, a value between 0 and 100. |
int? | mediumQuality | Compression quality for the medium form factor, a value between 0 and 100. |
int? | smallQuality | Compression quality for the small form factor, a value between 0 and 100. |
IProportions | largeCropToProportions | Override proportions constraints and any manual crop area and explicitly render the large form factor with these proportions. |
IProportions | mediumCropToProportions | Override proportions constraints and any manual crop area and explicitly render the medium form factor with these proportions. |
IProportions | smallCropToProportions | Override proportions constraints and any manual crop area and explicitly render the small form factor with these proportions. |
IDimensions | largeCropToSize | Override proportions constraints and any manual crop area and explicitly render the large form factor cropped to this size. |
IDimensions | mediumCropToSize | Override proportions constraints and any manual crop area and explicitly render the medium form factor cropped to this size. |
IDimensions | smallCropToSize | Override proportions constraints and any manual crop area and explicitly render the small form factor cropped to this size. |
Returns
Type | Description |
---|---|
HtmlString | HTML <picture> element. |
Type Parameters
Name | Description |
---|---|
TContent | The type of object that defines the AdaptiveImage property. |
TProperty | The type of AdaptiveImage property targeted by the lambda expression. |
Remarks
For most scenarios, it is preferable to use PropertyFor() instead of this method for rendering images.
RenderSingleImage(IHtmlHelper, ImageRenderSettings?)
Renders an image with specific render settings.
Declaration
public static HtmlString RenderSingleImage(this IHtmlHelper html, ImageRenderSettings? settings)
Parameters
Type | Name | Description |
---|---|---|
IHtmlHelper | html | Current HTML helper instance. |
ImageRenderSettings | settings | Settings for how the image should be rendered, including any cropping and/or scaling. |
Returns
Type | Description |
---|---|
HtmlString | HTML <img> element. |
Remarks
Note that this ignores any maximum rendering width specified through MaxWidth.
RenderSingleImage<TContent, TProperty>(IHtmlHelper<TContent>, Expression<Func<TContent, TProperty>>, int?, int?, bool, string?, string?, bool, int?, Proportions?, Dimensions?)
Renders an image using default render settings.
Declaration
public static HtmlString RenderSingleImage<TContent, TProperty>(this IHtmlHelper<TContent> html, Expression<Func<TContent, TProperty>> expression, int? width = null, int? maxWidth = null, bool ignoreConstraints = false, string? altText = null, string? cssClass = null, bool lazyLoad = false, int? quality = null, Proportions? cropToProportions = null, Dimensions? cropToSize = null) where TProperty : SingleImage
Parameters
Type | Name | Description |
---|---|---|
IHtmlHelper<TContent> | html | Current HTML helper instance. |
Expression<Func<TContent, TProperty>> | expression | Expression targeting the SingleImage property to render. |
int? | width | Final rendering width. |
int? | maxWidth | Maximum rendering width. |
bool | ignoreConstraints | Set to true to ignore any size or proportions constraints when rendering. |
string | altText | Alternate text to override any description set by the web editor. |
string | cssClass | CSS class to add to the img element. |
bool | lazyLoad | Whether image should be lazy loaded by the browser. |
int? | quality | Compression quality, a value between 0 and 100. |
Proportions | cropToProportions | Override proportions constraints and any manual crop area and explicitly render the image with these proportions. |
Dimensions | cropToSize | Override proportions constraints and any manual crop area and explicitly render the image cropped to this size. |
Returns
Type | Description |
---|---|
HtmlString | HTML <img> element. |
Type Parameters
Name | Description |
---|---|
TContent | The type of object that defines the SingleImage property. |
TProperty | The type of SingleImage property targeted by the lambda expression. |
Remarks
For most scenarios, it is preferable to use PropertyFor() instead of this method for rendering images. This method will not apply edit attributes for on-page editing.
Exceptions
Type | Condition |
---|---|
NotImplementedException | |
Exception |