In a typical MVC controller, we can bind the Json body with a Model as long as all the parameters match like so:
[HttpPost]
public void PostPerson(Person p){
//stuff
}
However, I noticed that using fiddler, if I were to do something like this:
{
"name":,
"age": 12
}
The controller will automatically return InternalServerError. I want to be able to return a custom message instead. How can I validate the Json if this was the scenario?
I initially thought that an invalid Json will result in the Person object becoming NULL, so I made a handler for that to return a custom message, but after trying it here, that doesn't appear to be the case.