Sachu
Sachu

Reputation: 7766

API with an parameter named with keyword word in c#

One of the API calling from outside company to our use the parameter name "ref". They asking us to create the web api which accept this parameter. We are writing in C# Web Api and "ref" is a keyword and wont able to do that. Any work around?

https://xxxxxxxxx/xxx/xxx/xxxxx/?ref=1234

Upvotes: 2

Views: 261

Answers (2)

vc 74
vc 74

Reputation: 38179

You can also use the Name property of FromUriAttribute:

public JsonResult MyMethod([FromUri(Name = "ref")] string reference)

Upvotes: 2

Rahul Sharma
Rahul Sharma

Reputation: 8302

You can accept ref as a parameter using@ symbol in front of your field:

public JsonResult MyMethod(string @ref)

You can read more here

Upvotes: 4

Related Questions