mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-01-19 17:51:45 +08:00
New version of Boolean Binder Provider (#8413)
* New version of Boolean Binder Provider * Use Convert.ToBoolean(string) rather than ValueProviderResult.ConvertTo(bool)
This commit is contained in:
committed by
GitHub
parent
6dc4f62a98
commit
b528ecd1e0
27
src/Orchard/Mvc/ModelBinders/BooleanBinderProvider.cs
Normal file
27
src/Orchard/Mvc/ModelBinders/BooleanBinderProvider.cs
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Web.Mvc;
|
||||||
|
|
||||||
|
namespace Orchard.Mvc.ModelBinders {
|
||||||
|
public class BooleanBinderProvider : IModelBinderProvider, IModelBinder {
|
||||||
|
|
||||||
|
public IEnumerable<ModelBinderDescriptor> GetModelBinders() {
|
||||||
|
return new[] {
|
||||||
|
new ModelBinderDescriptor {
|
||||||
|
ModelBinder = this,
|
||||||
|
Type = typeof(bool)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) {
|
||||||
|
var value = false;
|
||||||
|
try {
|
||||||
|
value = Convert.ToBoolean(bindingContext.ValueProvider.GetValue(bindingContext.ModelName).AttemptedValue);
|
||||||
|
} catch {
|
||||||
|
bindingContext.ModelState.AddModelError(bindingContext.ModelName, new FormatException());
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -182,6 +182,7 @@
|
|||||||
<Compile Include="Data\Migration\Schema\DropUniqueConstraintCommand.cs" />
|
<Compile Include="Data\Migration\Schema\DropUniqueConstraintCommand.cs" />
|
||||||
<Compile Include="Environment\Extensions\Models\LifecycleStatus.cs" />
|
<Compile Include="Environment\Extensions\Models\LifecycleStatus.cs" />
|
||||||
<Compile Include="Environment\ShellBuilders\ICompositionStrategy.cs" />
|
<Compile Include="Environment\ShellBuilders\ICompositionStrategy.cs" />
|
||||||
|
<Compile Include="Mvc\ModelBinders\BooleanBinderProvider.cs" />
|
||||||
<Compile Include="Mvc\Updater.cs" />
|
<Compile Include="Mvc\Updater.cs" />
|
||||||
<Compile Include="Recipes\Models\ConfigurationContext.cs" />
|
<Compile Include="Recipes\Models\ConfigurationContext.cs" />
|
||||||
<Compile Include="Recipes\Models\RecipeBuilderStepConfigurationContext.cs" />
|
<Compile Include="Recipes\Models\RecipeBuilderStepConfigurationContext.cs" />
|
||||||
|
|||||||
Reference in New Issue
Block a user