ViewDataDictionary<TModel> Class

 

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

Namespace:   System.Web.Mvc
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)

Inheritance Hierarchy

System.Object
  System.Web.Mvc.ViewDataDictionary
    System.Web.Mvc.ViewDataDictionary<TModel>

Syntax

public class ViewDataDictionary<TModel> : ViewDataDictionary
generic<typename TModel>
public ref class ViewDataDictionary : ViewDataDictionary
type ViewDataDictionary<'TModel> = 
    class
        inherit ViewDataDictionary
    end
Public Class ViewDataDictionary(Of TModel)
    Inherits ViewDataDictionary

Type Parameters

  • TModel
    The type of the model.

Constructors

Name Description
System_CAPS_pubmethod ViewDataDictionary<TModel>()

Initializes a new instance of the ViewDataDictionary<TModel> class.

System_CAPS_pubmethod ViewDataDictionary<TModel>(TModel)

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

System_CAPS_pubmethod ViewDataDictionary<TModel>(ViewDataDictionary)

Initializes a new instance of the ViewDataDictionary<TModel> class by using the specified view data dictionary.

Properties

Name Description
System_CAPS_pubproperty Count

Gets the number of elements in the collection.(Inherited from ViewDataDictionary.)

System_CAPS_pubproperty IsReadOnly

Gets a value that indicates whether the collection is read-only.(Inherited from ViewDataDictionary.)

System_CAPS_pubproperty Item[String]

Gets or sets the item that is associated with the specified key.(Inherited from ViewDataDictionary.)

System_CAPS_pubproperty Keys

Gets a collection that contains the keys of this dictionary.(Inherited from ViewDataDictionary.)

System_CAPS_pubproperty Model

Gets or sets the model.

System_CAPS_pubproperty ModelMetadata

Gets or sets information about the model.(Overrides ViewDataDictionary.ModelMetadata.)

System_CAPS_pubproperty ModelState

Gets the state of the model.(Inherited from ViewDataDictionary.)

System_CAPS_pubproperty TemplateInfo

Gets or sets an object that encapsulates information about the current template context.(Inherited from ViewDataDictionary.)

System_CAPS_pubproperty Values

Gets a collection that contains the values in this dictionary.(Inherited from ViewDataDictionary.)

Methods

Name Description
System_CAPS_pubmethod Add(KeyValuePair<String, Object>)

Adds the specified item to the collection.(Inherited from ViewDataDictionary.)

System_CAPS_pubmethod Add(String, Object)

Adds an element to the collection using the specified key and value .(Inherited from ViewDataDictionary.)

System_CAPS_pubmethod Clear()

Removes all items from the collection.(Inherited from ViewDataDictionary.)

System_CAPS_pubmethod Contains(KeyValuePair<String, Object>)

Determines whether the collection contains the specified item.(Inherited from ViewDataDictionary.)

System_CAPS_pubmethod ContainsKey(String)

Determines whether the collection contains an element that has the specified key.(Inherited from ViewDataDictionary.)

System_CAPS_pubmethod CopyTo(KeyValuePair<String, Object>[], Int32)

Copies the elements of the collection to an array, starting at a particular index.(Inherited from ViewDataDictionary.)

System_CAPS_pubmethod Equals(Object)

(Inherited from Object.)

System_CAPS_pubmethod Eval(String)

Evaluates the specified expression.(Inherited from ViewDataDictionary.)

System_CAPS_pubmethod Eval(String, String)

Evaluates the specified expression by using the specified format.(Inherited from ViewDataDictionary.)

System_CAPS_protmethod Finalize()

(Inherited from Object.)

System_CAPS_pubmethod GetEnumerator()

Returns an enumerator that can be used to iterate through the collection.(Inherited from ViewDataDictionary.)

System_CAPS_pubmethod GetHashCode()

(Inherited from Object.)

System_CAPS_pubmethod GetType()

(Inherited from Object.)

System_CAPS_pubmethod GetViewDataInfo(String)

Returns information about the view data as defined by the expression parameter.(Inherited from ViewDataDictionary.)

System_CAPS_protmethod MemberwiseClone()

(Inherited from Object.)

System_CAPS_pubmethod Remove(KeyValuePair<String, Object>)

Removes the first occurrence of a specified object from the collection.(Inherited from ViewDataDictionary.)

System_CAPS_pubmethod Remove(String)

Removes the element from the collection using the specified key.(Inherited from ViewDataDictionary.)

System_CAPS_protmethod SetModel(Object)

Sets the data model to use for the view.(Overrides ViewDataDictionary.SetModel(Object).)

System_CAPS_pubmethod ToString()

(Inherited from Object.)

System_CAPS_pubmethod TryGetValue(String, Object)

Attempts to retrieve the value that is associated with the specified key.(Inherited from ViewDataDictionary.)

Explicit Interface Implementations

Name Description
System_CAPS_pubinterfaceSystem_CAPS_privmethod IEnumerable.GetEnumerator()

Returns an enumerator that can be used to iterate through the collection.(Inherited from ViewDataDictionary.)

Remarks

You can use an instance of the strongly typed ViewDataDictionary<TModel> class in the same way that you use the loosely typed ViewDataDictionary class. An instance of the ViewDataDictionary<TModel> class is exposed by the ViewData property of the ViewPage<TModel> class.

To pass strongly typed data to a view, change the @ Page directive of the view so that the view inherits from ViewPage<TModel> instead of from ViewPage, as shown in the following example:

<%@ Page Inherits="ViewPage<Person>" %>

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

System.Web.Mvc Namespace

Return to top