c# - Cannot Convert List to Json -


i have following action method:

public class mydevicecontroller : apicontroller {     // api/<controller>     public jsonresult get()     {         int userid = -1;         list<string> mydevices1 = new list<string>();         mydevices1.add("1");         >> return json(mydevices1); << error here                } } 

the return underlined red following error:

cannot implicitly convert type (jsonresult list<string>) 

i using asp.net web api. think getting confused between using system.web.http , system.mvc.http h

your system confusing between

system.web.http.results.jsonresult<list<string>> 

and system.web.mvc.jsonresult

try specifiyng full name system.web.http.results.jsonresult>

public system.web.http.results.jsonresult<list<string>> get() {     int userid = -1;     list<string> mydevices1 = new list<string>();     mydevices1.add("1");     return json(mydevices1);    } 

another , preferred approach

public httpresponsemessage get() {     int userid = -1;     list<string> mydevices1 = new list<string>();     mydevices1.add("1");     return request.createresponse(mydevices1);    } 

in latter teh asp.net web api automatically negotiate between formats accepted client specified iin accepts header , send xml or json appropriately


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -