-1

I need to pass a string parameter as querystring parameter which should be optional.

public IHttpActionResult Test([FromUri] string Name, string Place)

Here I want Place as an optional parameter. I tried to use as string?Place=null. But It wont works for me. Let me know the solution for this.

mRhNs13
  • 479
  • 5
  • 25
  • Change your method signature: `public IHttpActionResult Test([FromUri] string Name, string Place = null)` – Ryan Wilson Sep 30 '21 at 13:37
  • Does this answer your question? [Optional query string parameters in ASP.NET Web API](https://stackoverflow.com/questions/11862069/optional-query-string-parameters-in-asp-net-web-api) – huMpty duMpty Sep 30 '21 at 13:42

2 Answers2

0

You were close:

public IHttpActionResult Test([FromUri] string Name, string Place = null)
JowJoris
  • 300
  • 1
  • 12
0

if you don't want to sen Place just don't put it in your url

...controller/test?Name=name

if you need both parameters

...controller/test?Name=name&Place=place

and you have to use FromUri for both parameters

public IHttpActionResult Test([FromUri] string Name, [FromUri]string Place)

or maybe you can try dont'use at all

public IHttpActionResult Test( string Name, string Place)
Serge
  • 40,935
  • 4
  • 18
  • 45