Click here to Skip to main content
14,236,234 members
Rate this:
Please Sign up or sign in to vote.
See more:
[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.
Rate this:
Please Sign up or sign in to vote.

Solution 2

Check these two lines:
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.
   
Rate this:
Please Sign up or sign in to vote.

Solution 1

I think the problem here is the await keyword is not used with async. Please change line
var response = client.DeleteAsync(uri).Result;

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


As asynchronous calls are used, we should use await keyword
   

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, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100