本文整理汇总了C#中ModelBindingExecutionContext类的典型用法代码示例。如果您正苦于以下问题:C# ModelBindingExecutionContext类的具体用法?C# ModelBindingExecutionContext怎么用?C# ModelBindingExecutionContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ModelBindingExecutionContext类属于命名空间,在下文中一共展示了ModelBindingExecutionContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: CreateAndPopulateComplexModel
private ComplexModel CreateAndPopulateComplexModel(ModelBindingExecutionContext modelBindingExecutionContext, ModelBindingContext bindingContext, IEnumerable<ModelMetadata> propertyMetadatas) {
// create a Complex Model and call into the Complex Model binder
ComplexModel originalComplexModel = new ComplexModel(bindingContext.ModelMetadata, propertyMetadatas);
ModelBindingContext complexModelBindingContext = new ModelBindingContext(bindingContext) {
ModelMetadata = MetadataProvider.GetMetadataForType(() => originalComplexModel, typeof(ComplexModel)),
ModelName = bindingContext.ModelName
};
IModelBinder complexModelBinder = bindingContext.ModelBinderProviders.GetRequiredBinder(modelBindingExecutionContext, complexModelBindingContext);
complexModelBinder.BindModel(modelBindingExecutionContext, complexModelBindingContext);
return (ComplexModel)complexModelBindingContext.Model;
}
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:12,代码来源:MutableObjectModelBinder.cs
示例17: NavigationDataValueProviderTest
public void NavigationDataValueProviderTest()
{
NavigationData data = new NavigationData() {
{ "string", "Hello" }, {"int", 1 }
};
StateController.Navigate("d0", data);
ModelBindingExecutionContext context = new ModelBindingExecutionContext(new MockHttpContext(), new ModelStateDictionary());
NavigationDataValueProvider provider = new NavigationDataValueProvider(context, false, null);
Assert.AreEqual("Hello", provider.GetValue("string").RawValue);
Assert.AreEqual(1, provider.GetValue("int").RawValue);
Assert.AreEqual("1", provider.GetValue("int").AttemptedValue);
}
开发者ID:ericziko,项目名称:navigation,代码行数:12,代码来源:NavigationDataBindingTest.cs
示例18: BindModel
public bool BindModel(ModelBindingExecutionContext modelBindingExecutionContext, ModelBindingContext bindingContext) {
ValueProviderResult vpResult = GetCompatibleValueProviderResult(bindingContext);
if (vpResult == null) {
return false; // conversion would have failed
}
bindingContext.ModelState.SetModelValue(bindingContext.ModelName, vpResult);
object model = vpResult.RawValue;
ModelBinderUtil.ReplaceEmptyStringWithNull(bindingContext.ModelMetadata, ref model);
bindingContext.Model = model;
return true;
}
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:13,代码来源:TypeMatchModelBinder.cs
示例19: GetResourceCommon
private static string GetResourceCommon(ModelBindingExecutionContext modelBindingExecutionContext, ModelMetadata modelMetadata, object incomingValue,
Func<ModelBindingExecutionContext, string> resourceAccessor)
{
string displayName = modelMetadata.GetDisplayName();
string str = resourceAccessor(modelBindingExecutionContext);
object[] objArray = new object[2];
objArray[0] = incomingValue;
objArray[1] = displayName;
string str1 = string.Format(CultureInfo.CurrentCulture, str, objArray);
return str1;
}
开发者ID:boatengfrankenstein,项目名称:SmartStoreNET,代码行数:13,代码来源:ErrorMessageProvider.cs
示例20: GetValidatorsForProperty
private IEnumerable<ModelValidator> GetValidatorsForProperty(ModelMetadata metadata, ModelBindingExecutionContext context) {
ICustomTypeDescriptor typeDescriptor = GetTypeDescriptor(metadata.ContainerType);
PropertyDescriptor property = typeDescriptor.GetProperties().Find(metadata.PropertyName, true);
if (property == null) {
throw new ArgumentException(
String.Format(
CultureInfo.CurrentCulture,
SR.GetString(SR.Common_PropertyNotFound),
metadata.ContainerType.FullName, metadata.PropertyName),
"metadata");
}
return GetValidators(metadata, context, property.Attributes.OfType<Attribute>());
}
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:14,代码来源:AssociatedValidatorProvider.cs
注:本文中的ModelBindingExecutionContext类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论