0

I'm using MVC 4 and Entity Framework 5 to build my website. To validate data in client side, I use Data Annotations. Here is my property in View Model:

public int Salary { get; set; }

As you can see, I don't put any annotation there. Also, in my database, the Salary column was marked as Allow null.

My problem is whenever I submit my form, the ModelState is invalid because of this property. It thinks that this property is required and display error on client side.

Do you know what causes the problem? Please help me. Thanks a lot.

1 Answer 1

2

The issue you are having is because the default constructor initializes the property to 0. If you want to allow nulls do this:public int? Salary { get; set; }

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.