本文整理汇总了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;
}
示例2: GetValueProvider
public override IValueProvider GetValueProvider(ModelBindingExecutionContext modelBindingExecutionContext) {
if (modelBindingExecutionContext == null) {
throw new ArgumentNullException("modelBindingExecutionContext");
}
return new FormValueProvider(modelBindingExecutionContext);
}
示例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
}
示例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(""));
}
示例5: GetValueProvider
public IValueProvider GetValueProvider(ModelBindingExecutionContext modelBindingExecutionContext) {
if (modelBindingExecutionContext == null) {
throw new ArgumentNullException("modelBindingExecutionContext");
}
return new UserProfileValueProvider(modelBindingExecutionContext);
}
示例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;
}
示例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;
}
}
示例8: ModelValidatingEventArgs
public ModelValidatingEventArgs(ModelBindingExecutionContext modelBindingExecutionContext, ModelValidationNode parentNode) {
if (modelBindingExecutionContext == null) {
throw new ArgumentNullException("modelBindingExecutionContext");
}
ModelBindingExecutionContext = modelBindingExecutionContext;
ParentNode = parentNode;
}
示例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;
}
示例10: DataAnnotationsModelValidator
public DataAnnotationsModelValidator(ModelMetadata metadata, ModelBindingExecutionContext context, ValidationAttribute attribute)
: base(metadata, context) {
if (attribute == null) {
throw new ArgumentNullException("attribute");
}
Attribute = attribute;
}
示例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;
}
}
示例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;
}
示例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;
}
示例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;
}
}
示例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;
}