Hi,
I am new to coding using MVC so I would be grateful if anyone was able to help me out, could you please keep it simple so I am able to understand
I have created an application which reads data from my web API and then places that data into a table on my MVC view.
I have got it all working but I am unsure on one bit of code in my MVC home controller I just found it on the internet and it worked for me but I wanted to actually understand what it was doing.
public ActionResult Student()
{
List lst = new List();
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:6193/");
client.DefaultRequestHeaders.Accept.Add(
new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = client.GetAsync("api/students").Result;
if (response.IsSuccessStatusCode)
{
//lst = response.Content.ReadAsAsync
- >().Result;
var content = response.Content;
var contentstream = content.ReadAsStringAsync().Result;
List students = System.Web.Helpers.Json.Decode
- >(contentstream);
return View(students);
}
return View(lst);
Thank you

Afzaal Ahmad ZeeshanPosted Nov 17, 2015, 4:57 AM
HttpResponseMessage response = client.GetAsync("api/students").Result;