I’m trying to pass a null value in a JSON object let’s say: { 'property': null } to a controller action in ASP.Net MVC but in the action method I see the property gets a zero value instead of null.
What can I do about this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
just dont send that property or delete that in the client-side :
delete x.yourPropertyfor example if you have some .net mvc controller with a nullable property like this:
public JsonResult SomeAction(decimal? yourProperty){ //your code goes here }if in the client-side you call some ajax request with
yourProperty: nullthe model binder will set it to 0, like as int or string that will be set toEmptyStringso if you want to send it as null you just avoid sending it, or if it’s a property that you have set before all you need is to just delete that property:
delete x.yourProperty