ASP.NET MVC UpdateModel() parameter conversion woes?

You could use a Regex attribute to contain the decimal to a precision of 9. This would also allow you to add a custom message when the Regex fails, such as "Your value may have a maximum of 9 places after the decimal. " or something similar.

Also if you have client side validation enabled, the Regex will work in both client and server side validation.

So after a couple of hours of head banging I settled on the following custom model binder for decimals. It makes sure that all decimal values are parseable before binding them. Public class TreasuryIndexRateDecimalBinder : DefaultModelBinder { public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { var providerResult = bindingContext.ValueProvider.

GetValue(bindingContext. ModelName); if (providerResult! = null) { decimal value; if (!decimal.

TryParse(providerResult. AttemptedValue, NumberStyles. Float, CultureInfo.

CurrentCulture, out value)) { // TODO: Decide whether to show an error // bindingContext.ModelState. AddModelError(bindingContext. ModelName, "error message"); return 0m; } return Math.

Round(value, 6); } return base. BindModel(controllerContext, bindingContext); } } The binding is set up in Application_Start() to register it for all decimal values. Protected void Application_Start() { ModelBinders.Binders.

Add(typeof(decimal), new TreasuryIndexRateDecimalBinder()); AreaRegistration. RegisterAllAreas(); RegisterRoutes(RouteTable. Routes); } Unless somebody comes along with a more interesting approach I think I'll stick with this.

The parameter conversion from type 'System. String' to type 'System. Digging into the errors reveals the cause.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions