Search code examples
javascriptc#angularodataasp.net-core-5.0

In Asp.Net core Odata, how to prevent filter string from replacing text passed


I am passing an odata query as below

http://localhost:5000/odata/Levels?$filter=contains(Code, '+14')

However when this lands in my controller I see that the filter object received is being replaced as

{contains(Code, ' 14')}

As you can see +14 is being replaced 14 where + is replaced with a space due to which my query is failing. How can I fix this issue?


Solution

  • Try it like this:

    http://localhost:5000/odata/Levels?$filter=contains(Code, encodeURIComponent('+14'))
    

    I don't know how you generate the rest of the URI but you should replace +14 with an encoded representation before sending it the the server.