public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
 {
     try
     {
         var value = bindingContext.GetValueFromValueProvider();
         bindingContext.ModelState.SetModelValue(bindingContext.ModelName, value);
         var rawValue = (value == null ? null : value.RawValue as string[]) ?? new string[] { };
         return _implicitConversionMethod.Invoke(null, new object[] { rawValue.SingleOrDefault() });
     }
     catch (TargetInvocationException ex)
     {
         bindingContext.ModelState.AddModelError(bindingContext.ModelName, ex.InnerException);
         return null;
     }
 }
 public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
 {
     try
     {
         var result = base.BindModel(controllerContext, bindingContext);
         return result;
     }
     catch (HttpRequestValidationException)
     {
         var modelState = new ModelState();
         modelState.Errors.Add(string.Format("'{0}' contains invalid characters", bindingContext.ModelMetadata.DisplayName ?? bindingContext.ModelMetadata.PropertyName));
         modelState.Value = bindingContext.GetValueFromValueProvider(false);
         bindingContext.ModelState.Add(bindingContext.ModelName, modelState);
     }
     return null;
 }
 private string GetUnvalidatedValue(
     ModelBindingContext bindingContext, string key)
 {
     var result = bindingContext.GetValueFromValueProvider(key, false);
     return (result == null) ? null : result.AttemptedValue;
 }