コード例 #1
0
        public async Task <IActionResult> Index()
        {
            List <StudentDTO> dto = new List <StudentDTO>();

            HttpClient client = _studentAPI.InitializeClient();

            HttpResponseMessage res = await client.GetAsync("api/student");

            //Checking the response is successful or not which is sent using HttpClient
            if (res.IsSuccessStatusCode)
            {
                //Storing the response details recieved from web api
                var result = res.Content.ReadAsStringAsync().Result;

                //Deserializing the response recieved from web api and storing into the Employee list
                dto = JsonConvert.DeserializeObject <List <StudentDTO> >(result);
            }
            //returning the employee list to view
            return(View(dto));
        }
コード例 #2
0
        public async Task <IActionResult> Index()
        {
            List <StudentDTO>   dto    = new List <StudentDTO>();
            HttpClient          client = _studentAPI.InitializeClient();
            HttpResponseMessage res    = await client.GetAsync("api/student");

            if (res.IsSuccessStatusCode)
            {
                var result = res.Content.ReadAsStringAsync().Result;
                dto = JsonConvert.DeserializeObject <List <StudentDTO> >(result);
            }
            return(View(dto));
        }