0

I've got a strange issue and can't figure it out. When I'm calling $http.get with params like

{oneId: 111
 twoId: 222
 stringValue: null}

then stringValue is absent and the request goes like

http://my-uri.com/action?oneId=111&twoId=222

But if stringValue setted as undefined then it goes ok. What's wrong there?

0

1 Answer 1

2

null is a reserved keyword, that's why it's behaving like that. You can resolve this in a number of way -

  1. as you are using asp.net web api - you can re-write your action -
public IHttpActionResult someAction(long oneId, long twoId, string stringValue = null)

In this way if stringValue doesn't get passed in param, then it will be received as null.

  1. you can send null as string int the get method -
{oneId: 111
 twoId: 222
 stringValue: "null"}

Sending an empty string("") instead of "null" is also an option.

  1. Also as per this answer - sending url encoded null value(%00) will also work.
Sign up to request clarification or add additional context in comments.

2 Comments

thanks! will be great if you will post links to docs to proof that (that null is reserved keyword)
@anatol, here you go null reserved keyword

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.