Dictionaryvalueprovider
Namevaluecollectionvalueprovider uses a namevaluecollection as a data source, and the type of dictionnaryvalueprovider data source is naturally a dictionnary. Both NameValueCollection and dictionnary are sets of key-value pairs, and the difference between them is that the NameValueCollection run element has the same key,dictionnary but requires the element's key to be unique.
First, dictionaryvalueprovider<tvalue>
The Dictionnaryvalueprovider type full name is System.web.mvc.dictionaryvalueprovider<tvalue>, as shown in the following code fragment. Dictionaryvalueprovider<tvalue> implements the Ienumerablevalueprovider and Ivalueprovider interfaces, and the constructor accepts a idictionary< String, Tvalue> object that represents the dictionary as the data source. There is no essential difference between the logic of all methods defined in Dictionaryvalueprovider<tvalue> and the method of the same name defined in Namevaluecollectionvalueprovider.
1:public class dictionaryvalueprovider<tvalue>: Ienumerablevalueprovider, Ivalueprovider
2: {
3: Public dictionaryvalueprovider (idictionary<string, tvalue> Dictionary, CultureInfo culture);
4: Public virtual bool Containsprefix (string prefix);
5: Public virtual idictionary<string, string> getkeysfromprefix (string prefix);
6: Public virtual Valueproviderresult GetValue (string key);
7:}
Second, Routedatavalueprovider
Inherits the current routing data as the routedatavalueprovider of the data source from dictionaryvalueprovider<tvalue>. As shown in the following code fragment, Routedatavalueprovider based on the current controller context will directly represent the values attribute of the Routedata object that represents the current routed data (this is a RouteValueDictionary object) as the data source.
1:public Sealed class Routedatavalueprovider:dictionaryvalueprovider<object>
2: {
3: Public Routedatavalueprovider (ControllerContext controllercontext):
4: Base (controllerContext.RouteData.Values, CultureInfo.InvariantCulture)
5: {
6: }
7:}
Third, Httpfilecollectionvalueprovider
We can upload files through the input elements of type file, and in the Httprequestbase object that represents the HTTP request, the upload file is represented by the read-only property files. As shown in the following code snippet, the property type is Httpfilecollectionbase and is a collection of element type HttpPostedFileBase.
1:public abstract class Httprequestbase
2: {
3:public virtual httpfilecollectionbase Files {ge T
4:}
5:public abstract class Httpfilecollectionbase:nameobjectcollectionbase, ICollection, IENUMERABLE
6: {
7:public virtual string[] AllKeys {get;}
8:public Override int Count {get;}
9:public Virtual HttpPostedFileBase this[int index] {get;}
10:public virtual HttpPostedFileBase this[string name] {get;}
11:}
12:public abstract class HttpPostedFileBase
: {
14:public virtual void SaveAs (string filename);
:
16:public virtual int contentlength {get;}
17:public Virtual string ContentType {get;}
18:public Virtual string FileName {get;}
19:public Virtual Stream inputstream {get;}
:}
The action method used to process the upload file usually defines a parameter of type HttpPostedFileBase and its list to represent the uploaded file. The data selected for the model binding for the HttpPostedFileBase parameter is derived from the Httprequestbase files attribute that represents the current request. The supply of the specific parameter value is finally realized by the Httpfilecollectionvalueprovider with the following definition.
1:public Sealed class Httpfilecollectionvalueprovider:dictionaryvalueprovider 2: {
3: Public Httpfilecollectionvalueprovider (ControllerContext controllercontext);
4:}