asp.net web api - web api - list variables on a class -


i'm doing code in web api , want list variables in model class, , show them

here web api's code:

   //method list variables class hello     [httpget]     [route("api/listofvariables")]     public ienumerable<string> listofvariables()     {         return typeof(hello).getfields()                                     .select(field => field.name)                                     .tolist();      } 

model class

  public class hello      {        public int helloid { get; set; }          public string name { get; set; }     }   } 

and web api config:

        config.routes.maphttproute(             name: "defaultapi",             routetemplate: "api/{controller}/{id}",             defaults: new { id = routeparameter.optional }         ); 

and when use following url: http://localhost:1861/api/listofvariables

i information:

  <arrayofstring xmlns:i="http://www.w3.org/2001/xmlschema-instance"          xmlns="http://schemas.microsoft.com/2003/10/serialization/arrays"/> 

can me? i'm new .net

the hello class doesn't have fields, you're seeing empty list. class has properties instead. can use getproperties() fetch those.

to illustrate:

class hello {     public int helloid; // field }  class hello {     public int helloid { get; set; } // property } 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -