本文整理汇总了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);
}
}
示例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);
}
示例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.");
}
示例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));
}
示例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;
}