0
votes

I'm writing web service in asp.net mvc and still having the same error connected with the code below:

    public ActionResult Edit(int C)
    {
        var customers = _ourCustomerRespository.GetCustomers();
        var std = customers.Where(s => s.CustomerID == C).FirstOrDefault();

        return View(std);
    }

    [System.Web.Http.HttpPost]
    public ActionResult Edit(Customer C)
    {
        return RedirectToAction("Index");
    }

and when i try use my service i have error message

The current request for action 'Edit' on controller type 'DefaultController' is ambiguous between the following action methods: System.Web.Mvc.ActionResult Edit(Int32) on type WebApplication2.Controllers.DefaultController System.Web.Mvc.ActionResult Edit(WebApplication2.Models.Customer) on type WebApplication2.Controllers.DefaultController

Can anybody help me with solving that?

1

1 Answers

2
votes

That's because you decorated your controller action with the wrong HttpPost attribute. You need this one:

[System.Web.Mvc.HttpPost]
public ActionResult Edit(Customer C)

The one you have used (System.Web.Http.HttpPost) is designed for ASP.NET Web API actions and has strictly zero effect when placed on an ASP.NET MVC controller action. So the ASP.NET MVC framework cannot disambiguate between the 2 Edit actions because they are using the same verb and thus you are getting the error.

Remark: please make sure that you tag your question correctly to avoid any confusions. Currently you have used the asp.net-web-api whereas the controller action you have shown is clearly asp.net-mvc. Those are 2 completely different frameworks.