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?

anatol
  • 1,680
  • 2
  • 24
  • 47

1 Answers1

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.
Arnab Roy
  • 619
  • 5
  • 16