Click here to Skip to main content
15,920,468 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
[HttpPost, ActionName("DeleteEmp")]
public async Task<ActionResult> DeleteEmp(int Id)
{
   using (HttpClient client = new HttpClient())
   {
string Url = "http://localhost:14316/api/employee";
       var uri = new Uri(string.Format(Url, Id));
       var response = client.DeleteAsync(uri).Result;
       if (response.IsSuccessStatusCode)
       {
          .......
       }              
       return View("GetEmployee", JsonConvert.DeserializeObject<IEnumerable<Employee>>(result));

   }
}
Posted
Updated 2-Feb-16 20:49pm
v2
Comments
Mohsin_Khan_ 3-Feb-16 3:05am    
Please, post Web API and api route config code also.

Check these two lines:
C#
string Url = "http://localhost:14316/api/employee";
var uri = new Uri(string.Format(Url, Id));

Are you missing something? What effect does the Id have here? Your api request does not contain any Id. So, I assume it is therefore not finding any matching api signature.

Also, async function needs await keyword.
 
Share this answer
 
I think the problem here is the await keyword is not used with async. Please change line
C#
var response = client.DeleteAsync(uri).Result;

to
C#
var response = await client.DeleteAsync(uri).Result;


As asynchronous calls are used, we should use await keyword
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900