Please disable your AD blocker to continue using this site. Ads help us keep the content free! please press keyboard F5 to refresh page after disabled AD blocker
// Note that getting a service from the current cache will return the same instance for every request. return Resolver.GetService<IAsyncActionInvoker>() ?? Resolver.GetService<IActionInvoker>() ?? new AsyncControllerActionInvoker(); }
privateobjectSimpleModelBinding(ControllerContext controllerContext, Type modelType) { object modelInstance = Activator.CreateInstance(modelType); foreach (PropertyInfo property in modelType.GetProperties()) { //針對基本型別或string型別給值 if (!property.CanWrite || IsSimpleType(property)) { object propertyValue; if (GetValueTypeInstance(controllerContext, property.Name, property.PropertyType, out propertyValue)) { property.SetValue(modelInstance, propertyValue); } } }
return modelInstance; }
privateboolGetValueTypeInstance(ControllerContext controllerContext, string modelName, Type modelType, outobjectvalue) { var form = controllerContext.RequestContext.HttpContext.Request.Form; var queryString = controllerContext.RequestContext.HttpContext.Request.QueryString;
privateboolGetValueTypeInstance(ControllerContext controllerContext, string modelName, Type modelType, outobjectvalue) { var form = controllerContext.RequestContext.HttpContext.Request.Form; var queryString = controllerContext.RequestContext.HttpContext.Request.QueryString;
privateboolGetValueTypeInstance(ControllerContext controllerContext, string modelName, Type modelType, outobjectvalue) { List<ValueProviderBase> _valueProvider = new List<ValueProviderBase>() { new FormValueProvider(controllerContext), new QueryStringValueProvider(controllerContext) };
foreach (var valueProvider in _valueProvider) { value = valueProvider.GetValue(modelName, modelType); if (value != null) returntrue; }
///<summary> /// Defines the methods that are required for a value provider in ASP.NET MVC. ///</summary> publicinterfaceIValueProvider { ///<summary> /// Determines whether the collection contains the specified prefix. ///</summary> boolContainsPrefix(string prefix);
///<summary> /// Retrieves a value object using the specified key. ///</summary> ValueProviderResult GetValue(string key); }