Table of Contents

Class ViewDataDictionary

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

Represents a container that is used to pass data between a controller and a view.

public class ViewDataDictionary : IDictionary<string, object>, ICollection<KeyValuePair<string, object>>, IEnumerable<KeyValuePair<string, object>>, IEnumerable
Inheritance
ViewDataDictionary
Implements
Derived
Inherited Members

Constructors

ViewDataDictionary()

Initializes a new instance of the ViewDataDictionary class.

public ViewDataDictionary()

ViewDataDictionary(object)

Initializes a new instance of the ViewDataDictionary class by using the specified model.

public ViewDataDictionary(object model)

Parameters

model object

The model.

ViewDataDictionary(ViewDataDictionary)

Initializes a new instance of the ViewDataDictionary class by using the specified dictionary.

public ViewDataDictionary(ViewDataDictionary dictionary)

Parameters

dictionary ViewDataDictionary

The dictionary.

Exceptions

ArgumentNullException

The dictionary parameter is null.

Properties

Count

Gets the number of elements in the collection.

public int Count { get; }

Property Value

int

The number of elements in the collection.

IsReadOnly

Gets a value that indicates whether the collection is read-only.

public bool IsReadOnly { get; }

Property Value

bool

true if the collection is read-only; otherwise, false.

this[string]

Gets or sets the item that is associated with the specified key.

public object this[string key] { get; set; }

Parameters

key string

Property Value

object

The value of the selected item.

Keys

Gets a collection that contains the keys of this dictionary.

public ICollection<string> Keys { get; }

Property Value

ICollection<string>

A collection that contains the keys of the object that implements IDictionary<TKey, TValue>.

Model

Gets or sets the model that is associated with the view data.

public object Model { get; set; }

Property Value

object

The model that is associated with the view data.

ModelMetadata

Gets or sets information about the model.

public virtual ModelMetadata ModelMetadata { get; set; }

Property Value

ModelMetadata

Information about the model.

ModelState

Gets the state of the model.

public ModelStateDictionary ModelState { get; }

Property Value

ModelStateDictionary

The state of the model.

TemplateInfo

Gets or sets an object that encapsulates information about the current template context.

public TemplateInfo TemplateInfo { get; set; }

Property Value

TemplateInfo

An object that contains information about the current template.

Values

Gets a collection that contains the values in this dictionary.

public ICollection<object> Values { get; }

Property Value

ICollection<object>

A collection that contains the values of the object that implements IDictionary<TKey, TValue>.

Methods

Add(KeyValuePair<string, object>)

Adds the specified item to the collection.

public void Add(KeyValuePair<string, object> item)

Parameters

item KeyValuePair<string, object>

The object to add to the collection.

Exceptions

NotSupportedException

The collection is read-only.

Add(string, object)

Adds an element to the collection using the specified key and value .

public void Add(string key, object value)

Parameters

key string

The key of the element to add.

value object

The value of the element to add.

Exceptions

NotSupportedException

The IDictionary<TKey, TValue> object is read-only.

ArgumentNullException

key is null.

ArgumentException

An element with the same key already exists in the IDictionary<TKey, TValue> object.

Clear()

Removes all items from the collection.

public void Clear()

Exceptions

NotSupportedException

The ICollection<T> object is read-only.

Contains(KeyValuePair<string, object>)

Determines whether the collection contains the specified item.

public bool Contains(KeyValuePair<string, object> item)

Parameters

item KeyValuePair<string, object>

The object to locate in the collection.

Returns

bool

true if item is found in the collection; otherwise, false.

ContainsKey(string)

Determines whether the collection contains an element that has the specified key.

public bool ContainsKey(string key)

Parameters

key string

The key of the element to locate in the collection.

Returns

bool

true if the collection contains an element that has the specified key; otherwise, false.

Exceptions

ArgumentNullException

key is null.

CopyTo(KeyValuePair<string, object>[], int)

Copies the elements of the collection to an array, starting at a particular index.

public void CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)

Parameters

array KeyValuePair<string, object>[]

The one-dimensional array that is the destination of the elements copied from the collection. The array must have zero-based indexing.

arrayIndex int

The zero-based index in array at which copying begins.

Exceptions

ArgumentNullException

array is null.

ArgumentOutOfRangeException

arrayIndex is less than 0.

ArgumentException

array is multidimensional.-or- arrayIndex is equal to or greater than the length of array.-or- The number of elements in the source collection is greater than the available space from arrayIndex to the end of the destination array.-or- Type T cannot be cast automatically to the type of the destination array.

Eval(string)

Evaluates the specified expression.

public object Eval(string expression)

Parameters

expression string

The expression.

Returns

object

The results of the evaluation.

Exceptions

ArgumentException

The expression parameter is null or empty.

Eval(string, string)

Evaluates the specified expression by using the specified format.

public string Eval(string expression, string format)

Parameters

expression string

The expression.

format string

The format.

Returns

string

The results of the evaluation.

GetEnumerator()

Returns an enumerator that can be used to iterate through the collection.

public IEnumerator<KeyValuePair<string, object>> GetEnumerator()

Returns

IEnumerator<KeyValuePair<string, object>>

An enumerator that can be used to iterate through the collection.

GetViewDataInfo(string)

Returns information about the view data as defined by the expression parameter.

public ViewDataInfo GetViewDataInfo(string expression)

Parameters

expression string

A set of key/value pairs that define the view-data information to return.

Returns

ViewDataInfo

An object that contains the view data information that is defined by the expression parameter.

Exceptions

ArgumentException

The expression parameter is either null or empty.

Remove(KeyValuePair<string, object>)

Removes the first occurrence of a specified object from the collection.

public bool Remove(KeyValuePair<string, object> item)

Parameters

item KeyValuePair<string, object>

The object to remove from the collection.

Returns

bool

true if item was successfully removed from the collection; otherwise, false. This method also returns false if item is not found in the collection.

Exceptions

NotSupportedException

The collection is read-only.

Remove(string)

Removes the element from the collection using the specified key.

public bool Remove(string key)

Parameters

key string

The key of the element to remove.

Returns

bool

true if the element is successfully removed; otherwise, false. This method also returns false if key was not found in the original collection.

Exceptions

NotSupportedException

The collection is read-only.

ArgumentNullException

key is null.

SetModel(object)

Sets the data model to use for the view.

protected virtual void SetModel(object value)

Parameters

value object

The data model to use for the view.

TryGetValue(string, out object)

Attempts to retrieve the value that is associated with the specified key.

public bool TryGetValue(string key, out object value)

Parameters

key string

The key of the value to get.

value object

When this method returns, the value that is associated with the specified key, if the key is found; otherwise, the default value for the type of the value parameter. This parameter is passed uninitialized.

Returns

bool

true if the collection contains an element with the specified key; otherwise, false.

Exceptions

ArgumentNullException

key is null.