Hello. This is what you could do to avoid this error. It seems that you do not have the client validation enabled. Probably once you enable it you will see the error message before the form submits.
On the server side, it is a good practice to invoke this method befor saving changes in the controller:
if (ModelState.IsValid)
That instruction will validate the model data and, in case there is no value for any required field, it will return false, so no attempt to save data into the DB will occur.
MatiasBeccar...
Member
46 Points
8 Posts
Re: Error when testing validation: 'This property cannot be set to a null value.'
Jun 14, 2012 12:03 PM|LINK
Hello. This is what you could do to avoid this error. It seems that you do not have the client validation enabled. Probably once you enable it you will see the error message before the form submits.
On the server side, it is a good practice to invoke this method befor saving changes in the controller:
if (ModelState.IsValid)
That instruction will validate the model data and, in case there is no value for any required field, it will return false, so no attempt to save data into the DB will occur.
Hope it helps!
Matías Beccaría