Search code examples
c#jqueryasp.net-mvcviewdata

ViewData.ModelState.IsValid is false because Mvc can't parse value which has separated hundreds and thousands with commas


I have fields of type int?.

On view i use jquery plugin which separate textBox value with commas like this : 3,463,436 = 3463436 - it's must be int value.

But on Form subbmit i get error "The value '3,463,436' is not valid for Maximum Contiguous."

Any advice? Thanks.


Solution

  • In ASP.NET MVC one option is to implement a custom ModelBinder that strips out commas from the submitted values. I.e. implement a subclass of DefaultModelBinder

    Here is how to do it for the decimal separator for the decimal data type:

    How to set decimal separators in ASP.NET MVC controllers?

    You will have to something similar for the thousands separator for the int data type.