Table of Contents

Class MediaViewModelExtensions

Namespace
Dynamicweb.Ecommerce.ProductCatalog
Assembly
Dynamicweb.Ecommerce.dll

Extension methods for MediaViewModel that resolve the underlying media type and return typed view models for images, files, and videos.

public static class MediaViewModelExtensions
Inheritance
MediaViewModelExtensions
Inherited Members

Remarks

Use these methods in Razor templates to determine how to render a media asset:

Methods

GetFileViewModel(MediaViewModel)

Returns a FileViewModel for the media asset without checking whether the file exists. Prefer TryGetFileViewModel(MediaViewModel, out FileViewModel) when you need to verify the file is present before rendering.

public static FileViewModel GetFileViewModel(this MediaViewModel mediaViewModel)

Parameters

mediaViewModel MediaViewModel

The media asset to convert.

Returns

FileViewModel

A FileViewModel built from Value.

GetVideoViewModel(MediaViewModel)

Returns a VideoViewModel for the media asset without checking whether it is a valid video. Prefer TryGetVideoViewModel(MediaViewModel, out VideoViewModel) when you need to verify the asset is a video before rendering.

public static VideoViewModel GetVideoViewModel(this MediaViewModel mediaViewModel)

Parameters

mediaViewModel MediaViewModel

The media asset to convert.

Returns

VideoViewModel

A VideoViewModel built from Value.

TryGetFileViewModel(MediaViewModel, out FileViewModel)

Tries to resolve the media asset as a file on disk.

public static bool TryGetFileViewModel(this MediaViewModel mediaViewModel, out FileViewModel fileViewModel)

Parameters

mediaViewModel MediaViewModel

The media asset to examine.

fileViewModel FileViewModel

When this method returns true, contains a FileViewModel with file metadata (path, size, etc.); otherwise null.

Returns

bool

true when Value is a non-empty path and the file exists on disk; false when the path is empty or the file cannot be found.

TryGetImageFileViewModel(MediaViewModel, out ImageFileViewModel)

Tries to resolve the media asset as an image file.

public static bool TryGetImageFileViewModel(this MediaViewModel mediaViewModel, out ImageFileViewModel imageFileViewModel)

Parameters

mediaViewModel MediaViewModel

The media asset to examine.

imageFileViewModel ImageFileViewModel

When this method returns true, contains an ImageFileViewModel with image metadata (dimensions, path, etc.); otherwise null.

Returns

bool

true when Value is a non-empty path to an existing image file; false when the path is empty, the file does not exist, or the file is not an image format.

TryGetVideoViewModel(MediaViewModel, out VideoViewModel)

Tries to resolve the media asset as a video.

public static bool TryGetVideoViewModel(this MediaViewModel mediaViewModel, out VideoViewModel videoViewModel)

Parameters

mediaViewModel MediaViewModel

The media asset to examine.

videoViewModel VideoViewModel

When this method returns true, contains a VideoViewModel suitable for rendering an embedded player; otherwise null.

Returns

bool

true when Value is either a video file on disk or a YouTube/Vimeo URL that can be embedded; false otherwise.

See Also

To top