using System; using System.Web.Mvc; namespace Neo.Afx.Mvc { public class DecimalModelBinder : DefaultModelBinder { #region Implementation of IModelBinder public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { var valueProviderResult = bindingContext.ValueProvider.GetValue(bindingContext.ModelName); if(valueProviderResult.AttemptedValue.Equals("N.aN") || valueProviderResult.AttemptedValue.Equals("NaN") || valueProviderResult.AttemptedValue.Equals("Infini.ty") || valueProviderResult.AttemptedValue.Equals("Infinity") || string.IsNullOrEmpty(valueProviderResult.AttemptedValue)) return 0m; return Convert.ToDecimal(valueProviderResult.AttemptedValue.Replace(" ", "").Replace(",", "")); } #endregion } }