Table of Contents

Class EnumHelper

Namespace
System.Web.Mvc.Html
Assembly
System.Web.Mvc.dll

Provides methods for working with enumeration values and select lists.

public static class EnumHelper
Inheritance
EnumHelper
Inherited Members

Methods

GetSelectList(Type)

Gets a list of SelectListItem objects corresponding to enum constants defined in the given type.

public static IList<SelectListItem> GetSelectList(Type type)

Parameters

type Type

The type to evaluate.

Returns

IList<SelectListItem>

A list for the given type.

GetSelectList(Type, Enum)

Gets a list of SelectListItem objects corresponding to enum constants defined in the given type. Also ensures the value will round-trip even if it does not match a defined constant and sets the Selected property to true for one element in the returned list -- matching the value.

public static IList<SelectListItem> GetSelectList(Type type, Enum value)

Parameters

type Type

The type to evaluate.

value Enum

The value from type to select.

Returns

IList<SelectListItem>

A list for the given type, possibly extended to include an unrecognized value.

GetSelectList(ModelMetadata)

Gets a list of SelectListItem objects corresponding to enum constants defined in the given metadata.

public static IList<SelectListItem> GetSelectList(ModelMetadata metadata)

Parameters

metadata ModelMetadata

The model metadata to evaluate.

Returns

IList<SelectListItem>

A list for the given metadata.

GetSelectList(ModelMetadata, Enum)

Gets a list of SelectListItem objects corresponding to enum constants defined in the given metadata. Also ensures the value will round-trip even if it does not match a defined constant and sets the Selected property to true for one element in the returned list -- matching the value.

public static IList<SelectListItem> GetSelectList(ModelMetadata metadata, Enum value)

Parameters

metadata ModelMetadata

The metadata to evaluate.

value Enum

Value from the type of metadata to select.

Returns

IList<SelectListItem>

A list for the given metadata, possibly extended to include an unrecognized value.

IsValidForEnumHelper(Type)

Gets a value indicating whether the given type or an expression of this type is suitable for use in GetSelectList(Type) and EnumDropDownListFor<TModel, TEnum>(HtmlHelper<TModel>, Expression<Func<TModel, TEnum>>) calls.

public static bool IsValidForEnumHelper(Type type)

Parameters

type Type

The type to check.

Returns

bool

true if GetSelectList(Type) will not throw when passed the given type and EnumDropDownListFor<TModel, TEnum>(HtmlHelper<TModel>, Expression<Func<TModel, TEnum>>) will not throw when passed an expression of this type; otherwise, false.

IsValidForEnumHelper(ModelMetadata)

Gets a value indicating whether the given metadata or associated expression is suitable for use in GetSelectList(ModelMetadata) and EnumDropDownListFor<TModel, TEnum>(HtmlHelper<TModel>, Expression<Func<TModel, TEnum>>) calls.

public static bool IsValidForEnumHelper(ModelMetadata metadata)

Parameters

metadata ModelMetadata

The metadata to check.

Returns

bool

true if GetSelectList(ModelMetadata) will return not throw when passed given ModelMetadata and EnumDropDownListFor<TModel, TEnum>(HtmlHelper<TModel>, Expression<Func<TModel, TEnum>>) will not throw when passed associated expression; otherwise, false.