I’m new to Web API, and I’m stuck at getting multiple values for Get(). What I’m trying to do is to pass in many values through the query string. Instead of having a Get(string .., string .., so on), I decided to go MVC style and do something like Get(RequestModel m). This returns a NullRef exception. e.g.:
For my ‘web request’, I’ve created a class:
RequestModel
{
public string Req1 {get;set;}
public string Req2 {get;set;}
public string Req3 {get;set;}
}
My Get function in the controller:
public ValuesController : ApiController
{
public Get(RequestModel m)
{
return m.Req1;
}
}
My url is:
http://localhost/api/values?Req1=test
Is this possible? If not, what’s the best way to do this? The only thing i can think of as an alternative is ParseQueryString().
You would need to explicitly set [FromUri] attribute like below:
public Get([FromUri] RequestModel m)