This is my Code and i Can't fatch data from api in xamarin.
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
{
public MainPage()
{
InitializeComponent();
}
public static List getPersons()
{
List lp = new List();
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
try
{
HttpResponseMessage response = client.GetAsync("http://localhost:51949/api/employee").Result;
if (response.IsSuccessStatusCode)
{
lp = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result).ToList();
}
}
catch
{
{
List lp = new List();
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
try
{
HttpResponseMessage response = client.GetAsync("http://localhost:51949/api/employee").Result;
if (response.IsSuccessStatusCode)
{
lp = JsonConvert.DeserializeObject(response.Content.ReadAsStringAsync().Result).ToList();
}
}
catch
{
}
return lp;
}
private async void Button_Clicked(object sender, EventArgs e)
{
var list = getPersons();
await Navigation.PushAsync(new ListOfEmployee());
}
}
}
private async void Button_Clicked(object sender, EventArgs e)
{
var list = getPersons();
await Navigation.PushAsync(new ListOfEmployee());
}
}

Ahsan SiddiqueRank #164 · 14.4K reputationPosted Dec 3, 2018, 11:41 PM EST
Mushtaq M ARank #176 · 13.8K reputationPosted Jan 26, 2019, 8:31 PM EST