public async Task <ActionResult> Details(string id) { List <TestClass> test = new List <TestClass>(); using (var client = new HttpClient()) { client.BaseAddress = new Uri(Baseurl); HttpResponseMessage response = await client.GetAsync("api/TestAPI/" + id); if (response.IsSuccessStatusCode) { sp_viewbyid_Result tresp = await response.Content.ReadAsAsync <sp_viewbyid_Result>(); TestClass testtemp = new TestClass() { id = tresp.id, fname = tresp.fname, lname = tresp.lname, email = tresp.email }; test.Add(testtemp); } else { ModelState.AddModelError(string.Empty, "Server error try after some time."); } } if (test == null) { return(HttpNotFound()); } return(View(test)); }
public async Task <ActionResult> Edit(int id) { try { List <TestClass> test = new List <TestClass>(); using (var client = new HttpClient()) { client.BaseAddress = new Uri(Baseurl); HttpResponseMessage response = await client.GetAsync("api/TestAPI/" + id); if (response.IsSuccessStatusCode) { sp_viewbyid_Result tresp = await response.Content.ReadAsAsync <sp_viewbyid_Result>(); TestClass testtemp = new TestClass() { id = tresp.id, fname = tresp.fname, lname = tresp.lname, email = tresp.email }; test.Add(testtemp); } else { ModelState.AddModelError(string.Empty, "Server error try after some time."); } } return(View(test)); } catch (Exception) { return(RedirectToAction("Index", "Test")); } }