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


C# ModelBindingContext.PropertyFilter方法代码示例

本文整理汇总了C#中System.Web.Mvc.ModelBindingContext.PropertyFilter方法的典型用法代码示例。如果您正苦于以下问题:C# ModelBindingContext.PropertyFilter方法的具体用法?C# ModelBindingContext.PropertyFilter怎么用?C# ModelBindingContext.PropertyFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Mvc.ModelBindingContext的用法示例。


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

示例1: CheckPropertyFilter

 private static void CheckPropertyFilter(ModelBindingContext bindingContext)
 {
     if (bindingContext.ModelType.GetProperties().Select(p => p.Name).Any(name => !bindingContext.PropertyFilter(name)))
     {
         throw new InvalidOperationException(MvcResources.ExtensibleModelBinderAdapter_PropertyFilterMustNotBeSet);
     }
 }
开发者ID:JokerMisfits,项目名称:linux-packaging-mono,代码行数:7,代码来源:ExtensibleModelBinderAdapter.cs

示例2: BindCslaModel

        // add property filter described by BindAttribute, override prefix
        protected override object BindCslaModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            if (string.IsNullOrEmpty(BindCriteria.Include) && string.IsNullOrEmpty(BindCriteria.Exclude) && string.IsNullOrEmpty(BindCriteria.Prefix))
                return base.BindCslaModel(controllerContext, bindingContext);

            Predicate<string> propFilter = bindingContext.PropertyFilter;
            if (!string.IsNullOrEmpty(BindCriteria.Include) || !string.IsNullOrEmpty(BindCriteria.Exclude))
            {
                var bindAttr = new BindAttribute() { Exclude = BindCriteria.Exclude, Include = BindCriteria.Include };
                propFilter = (propName) => bindAttr.IsPropertyAllowed(propName)
                                                                && bindingContext.PropertyFilter(propName);
            }

            var newPrefix = BindCriteria.Prefix ?? bindingContext.ModelName;

            var newBindingContext = new ModelBindingContext()
                                        {
                                            Model = bindingContext.Model,
                                            ModelName = newPrefix,
                                            ModelState = bindingContext.ModelState,
                                            ModelType = bindingContext.ModelType,
                                            PropertyFilter = propFilter,
                                            ValueProvider = bindingContext.ValueProvider
                                        };

            return base.BindCslaModel(controllerContext, newBindingContext);
        }
开发者ID:transformersprimeabcxyz,项目名称:cslacontrib-MarimerLLC,代码行数:28,代码来源:CslaBindModelBinder.cs

示例3: CopyConstructor

        public void CopyConstructor() {
            // Arrange
            ModelBindingContext originalBindingContext = new ModelBindingContext() {
                FallbackToEmptyPrefix = true,
                ModelMetadata = new EmptyModelMetadataProvider().GetMetadataForType(null, typeof(object)),
                ModelName = "theName",
                ModelState = new ModelStateDictionary(),
                PropertyFilter = _ => false,
                ValueProvider = new SimpleValueProvider()
            };

            // Act
            ModelBindingContext newBindingContext = new ModelBindingContext(originalBindingContext);

            // Assert
            Assert.IsFalse(newBindingContext.FallbackToEmptyPrefix, "Property 'FallbackToEmptyPrefix' should not have been propagated.");
            Assert.IsNull(newBindingContext.ModelMetadata, "Property 'ModelMetadata' should not have been propagated.");
            Assert.AreEqual("", newBindingContext.ModelName, "Property 'ModelName' should not have been propagated.");
            Assert.AreEqual(originalBindingContext.ModelState, newBindingContext.ModelState, "Property 'ModelState' should have been propagated.");
            Assert.IsTrue(newBindingContext.PropertyFilter("foo"), "Property 'PropertyFilter' should not have been propagated.");
            Assert.AreEqual(originalBindingContext.ValueProvider, newBindingContext.ValueProvider, "Property 'ValueProvider' should have been propagated.");
        }
开发者ID:jesshaw,项目名称:ASP.NET-Mvc-3,代码行数:22,代码来源:ModelBindingContextTest.cs

示例4: GetKeys

 private IEnumerable<string> GetKeys(ModelBindingContext bindingContext)
 {
     var keys = new List<string> { bindingContext.ModelName, bindingContext.ModelName + ".Id", bindingContext.ModelName + "Id" };
     return keys.Where(x => bindingContext.PropertyFilter(x));
 }
开发者ID:Gilligan128,项目名称:Maelstrom,代码行数:5,代码来源:FromNHibernateModelBinder.cs

示例5: CreateComplexElementalModelBindingContext

        private ModelBindingContext CreateComplexElementalModelBindingContext(ControllerContext controllerContext, ModelBindingContext bindingContext, object model)
        {
            BindAttribute bindAttr = (BindAttribute)GetTypeDescriptor(controllerContext, bindingContext).GetAttributes()[typeof(BindAttribute)];
            Predicate<string> newPropertyFilter = (bindAttr != null)
                                                      ? propertyName => bindAttr.IsPropertyAllowed(propertyName) && bindingContext.PropertyFilter(propertyName)
                                                      : bindingContext.PropertyFilter;

            ModelBindingContext newBindingContext = new ModelBindingContext()
            {
                ModelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => model, bindingContext.ModelType),
                ModelName = bindingContext.ModelName,
                ModelState = bindingContext.ModelState,
                PropertyFilter = newPropertyFilter,
                ValueProvider = bindingContext.ValueProvider
            };

            return newBindingContext;
        }
开发者ID:Gilligan128,项目名称:Maelstrom,代码行数:18,代码来源:FromNHibernateModelBinder.cs


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