简体   繁体   中英

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?

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?

Replace the + with %2B , then the odata query like this:

http://localhost:5000/odata/Levels?$filter=contains(Code, '%2B14')

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM