How to Call MVC web Controller from Xamarin Android App -


string apiurl1 = string.format(@"http://xxx.xxx.x.xxx/test/home/getdata?id=1");  public static string getdata(string url)     {          string result = "";         try         {             using (webclient client = new webclient())             {                 result = client.downloadstring(string.format(@"" + url + ""));               }         }         catch (exception e)         {             string msg = e.message;             result = "";         }         return result;     } 

i trying data published .net mvc web project getting server error "the remote server returned error: (500) internal server error."

my mvc controller code here

public jsonresult getdata(int? id)     {         list<items> dbitems = items.getitemsdata(id);          return json(dbitems, jsonrequestbehavior.allowget);     } 

besides fact better suited using asp.net web api (you wouldn't have convert response json on controller), can try below. far server error, have debug server side.

  public class restclient   {       httpclient client;     private string resturl = "http://192.168.1.103/test/home/";     private static list<items> _items = new list<items>();      public restclient()     {         client = new httpclient();         client.maxresponsecontentbuffersize = 9999999;     }      public async task<list<item>> getitems(int? id)     {                      list<item> items= new list<item>();          var uri = new uri(resturl + "getdata?id=" + id);          var response = await client.getasync(uri);          if (response.issuccessstatuscode)          {             var content = await response.content.readasstringasync();             items= jsonconvert.deserializeobject<list<item>>(content);             _items.addrange(items);          }          else          {             //do          }              return _items;     }  } 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

android - CoordinatorLayout, FAB and container layout conflict -