ViewDataDictionary Class¶
- Namespace
Microsoft.AspNetCore.Mvc.ViewFeatures
- Assemblies
- Microsoft.AspNetCore.Mvc.ViewFeatures
Syntax¶
public class ViewDataDictionary : IDictionary<string, object>, ICollection<KeyValuePair<string, object>>, IEnumerable<KeyValuePair<string, object>>, IEnumerable
-
class
Microsoft.AspNetCore.Mvc.ViewFeatures.
ViewDataDictionary
Constructors¶
-
ViewDataDictionary
(Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider, Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary)¶ Initializes a new instance of the
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary
class.Arguments: - metadataProvider (Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider) –
Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider
instance used to createMicrosoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer
instances. - modelState (Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary) –
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary
instance for this scope.
public ViewDataDictionary(IModelMetadataProvider metadataProvider, ModelStateDictionary modelState)
- metadataProvider (Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider) –
-
ViewDataDictionary
(Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider, Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary, System.Type) Initializes a new instance of the
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary
class.Arguments: - metadataProvider (Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider) –
Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider
instance used to createMicrosoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer
instances. - modelState (Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary) –
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary
instance for this scope. - declaredModelType (System.Type) –
System.Type
ofMicrosoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.Model
values expected. Used to setMicrosoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.ModelMetadata
.
protected ViewDataDictionary(IModelMetadataProvider metadataProvider, ModelStateDictionary modelState, Type declaredModelType)
- metadataProvider (Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider) –
-
ViewDataDictionary
(Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider, System.Type) Initializes a new instance of the
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary
class.Arguments: - metadataProvider (Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider) –
Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider
instance used to createMicrosoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer
instances. - declaredModelType (System.Type) –
System.Type
ofMicrosoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.Model
values expected. Used to setMicrosoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.ModelMetadata
.
protected ViewDataDictionary(IModelMetadataProvider metadataProvider, Type declaredModelType)
- metadataProvider (Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider) –
-
ViewDataDictionary
(Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary) Initializes a new instance of the
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary
class based entirely on an existing instance.Arguments: source (Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary) – Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary
instance to copy initial values from.public ViewDataDictionary(ViewDataDictionary source)
-
ViewDataDictionary
(Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary, System.Object, System.Type) Initializes a new instance of the
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary
class based in part on an existing instance. This constructor is careful to avoid exceptionsMicrosoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.SetModel(System.Object)
may throw when <em>model</em> is <code>null</code>.Arguments: - source (Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary) –
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary
instance to copy initial values from. - model (System.Object) – Value for the
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.Model
property. - declaredModelType (System.Type) –
System.Type
ofMicrosoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.Model
values expected. Used to setMicrosoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.ModelMetadata
.
protected ViewDataDictionary(ViewDataDictionary source, object model, Type declaredModelType)
- source (Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary) –
-
ViewDataDictionary
(Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary, System.Type) Initializes a new instance of the
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary
class based in part on an existing instance.Arguments: - source (Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary) –
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary
instance to copy initial values from. - declaredModelType (System.Type) –
System.Type
ofMicrosoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.Model
values expected. Used to setMicrosoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.ModelMetadata
.
protected ViewDataDictionary(ViewDataDictionary source, Type declaredModelType)
- source (Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary) –
-
Methods¶
-
Add
(System.Collections.Generic.KeyValuePair<System.String, System.Object>)¶ public void Add(KeyValuePair<string, object> item)
-
Add
(System.String, System.Object) public void Add(string key, object value)
-
Clear
()¶ public void Clear()
-
Contains
(System.Collections.Generic.KeyValuePair<System.String, System.Object>)¶ Return type: System.Boolean public bool Contains(KeyValuePair<string, object> item)
-
ContainsKey
(System.String)¶ Return type: System.Boolean public bool ContainsKey(string key)
-
CopyTo
(System.Collections.Generic.KeyValuePair<System.String, System.Object>[], System.Int32)¶ public void CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)
-
Eval
(System.String)¶ Gets value of named <em>expression</em> in this
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary
.Arguments: expression (System.String) – Expression name, relative to the current model. Return type: System.Object Returns: Value of named <em>expression</em> in this Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary
.public object Eval(string expression)
-
Eval
(System.String, System.String) Gets value of named <em>expression</em> in this
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary
, formatted using given <em>format</em>.Arguments: - expression (System.String) – Expression name, relative to the current model.
- format (System.String) – The composite format
System.String
(see http://msdn.microsoft.com/en-us/library/txafckwd.aspx).
Return type: System.String
Returns: Value of named <em>expression</em> in this
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary
, formatted using given <em>format</em>.public string Eval(string expression, string format)
-
FormatValue
(System.Object, System.String)¶ Formats the given <em>value</em> using given <em>format</em>.
Arguments: - value (System.Object) – The value to format.
- format (System.String) – The composite format
System.String
(see http://msdn.microsoft.com/en-us/library/txafckwd.aspx).
Return type: System.String
Returns: The formatted
System.String
.public static string FormatValue(object value, string format)
-
GetViewDataInfo
(System.String)¶ Gets
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataInfo
for named <em>expression</em> in thisMicrosoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary
.Arguments: expression (System.String) – Expression name, relative to the current model. Return type: Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataInfo Returns: Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataInfo
for named <em>expression</em> in thisMicrosoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary
.public ViewDataInfo GetViewDataInfo(string expression)
-
Remove
(System.Collections.Generic.KeyValuePair<System.String, System.Object>)¶ Return type: System.Boolean public bool Remove(KeyValuePair<string, object> item)
-
Remove
(System.String) Return type: System.Boolean public bool Remove(string key)
-
SetModel
(System.Object)¶ Set
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.ModelExplorer
to ensureMicrosoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.Model
andMicrosoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer.Model
reflect the new <em>value</em>.Arguments: value (System.Object) – New Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.Model
value.protected virtual void SetModel(object value)
-
GetEnumerator
()¶ Return type: System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<System.String>> IEnumerator<KeyValuePair<string, object>> IEnumerable<KeyValuePair<string, object>>.GetEnumerator()
-
GetEnumerator
() Return type: System.Collections.IEnumerator IEnumerator IEnumerable.GetEnumerator()
-
TryGetValue
(System.String, out System.Object)¶ Return type: System.Boolean public bool TryGetValue(string key, out object value)
-
Properties¶
-
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.
Count
¶ Return type: System.Int32 public int Count { get; }
-
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.
IsReadOnly
¶ Return type: System.Boolean public bool IsReadOnly { get; }
-
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.
Item[System.String]
¶ Return type: System.Object public object this[string index] { get; set; }
-
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.
Keys
¶ Return type: System.Collections.Generic.ICollection<System.String> public ICollection<string> Keys { get; }
-
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.
Model
¶ Gets or sets the current model.
Return type: System.Object public object Model { get; set; }
-
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.
ModelExplorer
¶ Gets or sets the
Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer
for theMicrosoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.Model
.Return type: Microsoft.AspNetCore.Mvc.ViewFeatures.ModelExplorer public ModelExplorer ModelExplorer { get; set; }
-
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.
ModelMetadata
¶ Gets the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata
for an expression, theMicrosoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.Model
(if non-<code>null</code>), or the declaredSystem.Type
.Return type: Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata public ModelMetadata ModelMetadata { get; }
-
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.
ModelState
¶ Gets the
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary
.Return type: Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary public ModelStateDictionary ModelState { get; }
-
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.
TemplateInfo
¶ Gets the
Microsoft.AspNetCore.Mvc.ViewFeatures.TemplateInfo
.Return type: Microsoft.AspNetCore.Mvc.ViewFeatures.TemplateInfo public TemplateInfo TemplateInfo { get; }
-
Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.
Values
¶ Return type: System.Collections.Generic.ICollection<System.Object> public ICollection<object> Values { get; }
-