当前位置: 首页>>代码示例>>C#>>正文


C# ModelBindingExecutionContext类代码示例

本文整理汇总了C#中ModelBindingExecutionContext的典型用法代码示例。如果您正苦于以下问题:C# ModelBindingExecutionContext类的具体用法?C# ModelBindingExecutionContext怎么用?C# ModelBindingExecutionContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ModelBindingExecutionContext类属于命名空间,在下文中一共展示了ModelBindingExecutionContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BindModel

        public bool BindModel(ModelBindingExecutionContext modelBindingExecutionContext, ModelBindingContext bindingContext) {
            ModelBinderUtil.ValidateBindingContext(bindingContext);

            ValueProviderResult vpResult = bindingContext.UnvalidatedValueProvider.GetValue(bindingContext.ModelName, skipValidation: !bindingContext.ValidateRequest);
            if (vpResult == null) {
                return false; // no entry
            }

            object newModel;
            bindingContext.ModelState.SetModelValue(bindingContext.ModelName, vpResult);
            try {
                newModel = vpResult.ConvertTo(bindingContext.ModelType);
            }
            catch (Exception ex) {
                if (IsFormatException(ex)) {
                    // there was a type conversion failure
                    string errorString = ModelBinderErrorMessageProviders.TypeConversionErrorMessageProvider(modelBindingExecutionContext, bindingContext.ModelMetadata, vpResult.AttemptedValue);
                    if (errorString != null) {
                        bindingContext.ModelState.AddModelError(bindingContext.ModelName, errorString);
                    }
                }
                else {
                    bindingContext.ModelState.AddModelError(bindingContext.ModelName, ex);
                }
                return false;
            }

            ModelBinderUtil.ReplaceEmptyStringWithNull(bindingContext.ModelMetadata, ref newModel);
            bindingContext.Model = newModel;
            return true;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:31,代码来源:TypeConverterModelBinder.cs

示例2: GetValueProvider

        public override IValueProvider GetValueProvider(ModelBindingExecutionContext modelBindingExecutionContext) {
            if (modelBindingExecutionContext == null) {
                throw new ArgumentNullException("modelBindingExecutionContext");
            }

            return new FormValueProvider(modelBindingExecutionContext);
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:7,代码来源:FormAttribute.cs

示例3: BindModel

        public bool BindModel(ModelBindingExecutionContext modelBindingExecutionContext, ModelBindingContext bindingContext) {
            ModelBindingContext newBindingContext = bindingContext;
            IModelBinder binder = Providers.GetBinder(modelBindingExecutionContext, bindingContext);
            if (binder == null && !String.IsNullOrEmpty(bindingContext.ModelName)
                && bindingContext.ModelMetadata.IsComplexType) {

                // fallback to empty prefix?
                newBindingContext = new ModelBindingContext(bindingContext) { 
                    ModelName = String.Empty,
                    ModelMetadata = bindingContext.ModelMetadata
                };
                binder = Providers.GetBinder(modelBindingExecutionContext, newBindingContext);
            }

            if (binder != null) {
                bool boundSuccessfully = binder.BindModel(modelBindingExecutionContext, newBindingContext);
                if (boundSuccessfully) {
                    // run validation
                    newBindingContext.ValidationNode.Validate(modelBindingExecutionContext, parentNode:null);
                    return true;
                }
            }

            return false; // something went wrong
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:25,代码来源:DefaultModelBinder.cs

示例4: BlankKeyValueProviderTest

		public void BlankKeyValueProviderTest()
		{
			StateController.Navigate("d0");
			ModelBindingExecutionContext context = new ModelBindingExecutionContext(new MockHttpContext(), new ModelStateDictionary());
			NavigationDataValueProvider provider = new NavigationDataValueProvider(context, false, null);
			Assert.IsNull(provider.GetValue(""));
		}
开发者ID:ericziko,项目名称:navigation,代码行数:7,代码来源:NavigationDataBindingTest.cs

示例5: GetValueProvider

        public IValueProvider GetValueProvider(ModelBindingExecutionContext modelBindingExecutionContext) {
            if (modelBindingExecutionContext == null) {
                throw new ArgumentNullException("modelBindingExecutionContext");
            }

            return new UserProfileValueProvider(modelBindingExecutionContext);
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:7,代码来源:UserProfileAttribute.cs

示例6: BindModel

 public bool BindModel(ModelBindingExecutionContext modelBindingExecutionContext,
     System.Web.ModelBinding.ModelBindingContext bindingContext)
 {
     var valueProviderResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName);
     bindingContext.Model = BindModelImpl(valueProviderResult != null ? valueProviderResult.AttemptedValue : null);
     return bindingContext.Model != null;
 }
开发者ID:rodmjay,项目名称:ScaffR-Generated,代码行数:7,代码来源:DbGeographyModelBinder.cs

示例7: BindModel

            public bool BindModel(ModelBindingExecutionContext modelBindingExecutionContext, ModelBindingContext bindingContext) {
                ModelBinderUtil.ValidateBindingContext(bindingContext);
                ValueProviderResult vpResult = bindingContext.UnvalidatedValueProvider.GetValue(bindingContext.ModelName);

                // case 1: there was no <input ... /> element containing this data
                if (vpResult == null) {
                    return false;
                }

                string base64string = (string)vpResult.ConvertTo(typeof(string));

                // case 2: there was an <input ... /> element but it was left blank
                if (String.IsNullOrEmpty(base64string)) {
                    return false;
                }

                // Future proofing. If the byte array is actually an instance of System.Data.Linq.Binary
                // then we need to remove these quotes put in place by the ToString() method.
                string realValue = base64string.Replace("\"", String.Empty);
                try {
                    bindingContext.Model = ConvertByteArray(Convert.FromBase64String(realValue));
                    return true;
                }
                catch {
                    // corrupt data - just ignore
                    return false;
                }
            }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:28,代码来源:BinaryDataModelBinderProvider.cs

示例8: ModelValidatingEventArgs

        public ModelValidatingEventArgs(ModelBindingExecutionContext modelBindingExecutionContext, ModelValidationNode parentNode) {
            if (modelBindingExecutionContext == null) {
                throw new ArgumentNullException("modelBindingExecutionContext");
            }

            ModelBindingExecutionContext = modelBindingExecutionContext;
            ParentNode = parentNode;
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:8,代码来源:ModelValidatingEventArgs.cs

示例9: GetBinder

 public override System.Web.ModelBinding.IModelBinder GetBinder(
     ModelBindingExecutionContext modelBindingExecutionContext,
     System.Web.ModelBinding.ModelBindingContext bindingContext)
 {
     if (bindingContext.ModelType == typeof (DbGeography))
         return new DbGeographyModelBinder();
     return null;
 }
开发者ID:rodmjay,项目名称:ScaffR-Generated,代码行数:8,代码来源:DbGeographyModelBinder.cs

示例10: DataAnnotationsModelValidator

        public DataAnnotationsModelValidator(ModelMetadata metadata, ModelBindingExecutionContext context, ValidationAttribute attribute)
            : base(metadata, context) {

            if (attribute == null) {
                throw new ArgumentNullException("attribute");
            }

            Attribute = attribute;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:9,代码来源:DataAnnotationsModelValidator.cs

示例11: GetBinder

        public override IModelBinder GetBinder(ModelBindingExecutionContext modelBindingExecutionContext, ModelBindingContext bindingContext) {
            ModelBinderUtil.ValidateBindingContext(bindingContext);

            if (bindingContext.UnvalidatedValueProvider.ContainsPrefix(bindingContext.ModelName)) {
                return CollectionModelBinderUtil.GetGenericBinder(typeof(IDictionary<,>), typeof(Dictionary<,>), typeof(DictionaryModelBinder<,>), bindingContext.ModelMetadata);
            }
            else {
                return null;
            }
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:10,代码来源:DictionaryModelBinderProvider.cs

示例12: GetBinder

        public override IModelBinder GetBinder(ModelBindingExecutionContext modelBindingExecutionContext, ModelBindingContext bindingContext) {
            ModelBinderUtil.ValidateBindingContext(bindingContext);

            if (!bindingContext.ModelMetadata.IsReadOnly && bindingContext.ModelType.IsArray &&
                bindingContext.UnvalidatedValueProvider.ContainsPrefix(bindingContext.ModelName)) {
                Type elementType = bindingContext.ModelType.GetElementType();
                return (IModelBinder)Activator.CreateInstance(typeof(ArrayModelBinder<>).MakeGenericType(elementType));
            }

            return null;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:11,代码来源:ArrayModelBinderProvider.cs

示例13: ModelValidator

        protected ModelValidator(ModelMetadata metadata, ModelBindingExecutionContext modelBindingExecutionContext) {
            if (metadata == null) {
                throw new ArgumentNullException("metadata");
            }
            if (modelBindingExecutionContext == null) {
                throw new ArgumentNullException("modelBindingExecutionContext");
            }

            Metadata = metadata;
            ModelBindingExecutionContext = modelBindingExecutionContext;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:11,代码来源:ModelValidator.cs

示例14: GetUserResourceString

		private static string GetUserResourceString(ModelBindingExecutionContext modelBindingExecutionContext, string resourceName, string resourceClassKey)
		{
			if (string.IsNullOrEmpty(resourceClassKey) || modelBindingExecutionContext == null || modelBindingExecutionContext.HttpContext == null)
			{
				return null;
			}
			else
			{
				return modelBindingExecutionContext.HttpContext.GetGlobalResourceObject(resourceClassKey, resourceName, CultureInfo.CurrentUICulture) as string;
			}
		}
开发者ID:boatengfrankenstein,项目名称:SmartStoreNET,代码行数:11,代码来源:ErrorMessageProvider.cs

示例15: GetBinder

        public override IModelBinder GetBinder(ModelBindingExecutionContext modelBindingExecutionContext, ModelBindingContext bindingContext) {
            ModelBinderUtil.ValidateBindingContext(bindingContext);

            if (bindingContext.ModelType == ModelType) {
                if (SuppressPrefixCheck || bindingContext.UnvalidatedValueProvider.ContainsPrefix(bindingContext.ModelName)) {
                    return _modelBinderFactory();
                }
            }

            return null;
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:11,代码来源:SimpleModelBinderProvider.cs


注:本文中的ModelBindingExecutionContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。