Question

I have a hidden field which is bound to a int Id in the model, it has a required attribute and some fancy ajax code to set the id client side, the problem is that zero should be acounted as empty. Now the validation will succeed even if no Id has been selected, bow can I set which value should be counted as empty? I hope i do not need to create a custom validator for it.

Thanks

Was it helpful?

Solution

It doesn't maker sense to add required attribute to a non nullable type such as Int32. Value types are always required. You could use a nullable integer instead:

[Required]
public int? SomeProperty { get; set; }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top