Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

already defines a member called 'Create' with the same parameter types [duplicate]

I Have two method and distinct by http verb:

public class ProductImageController : Controller
{
     [HttpGet]
     public ViewResult Create(int productId)
          {
             return View(productId);
          }

      [HttpPost]
      public ViewResult Create(int productId)
          {
          }
}

but Get Error:

already defines a member called 'Create' with the same parameter types

like image 772
Mohammadreza Avatar asked Nov 18 '13 08:11

Mohammadreza


2 Answers

You can't have multiple methods with the same signature within the same scope like that i.e. same return type and parameter type.

EDIT- Looks like you need to use this: Related question

public class ProductImageController : Controller
{
     [HttpGet]
     public ViewResult Create(int productId)
     {
         return View(productId);
     }

    [HttpPost]
    [ActionName("Create")]
    public ViewResult CreatePost(int productId)
    {
        //return a View() somewhere in here
    }
}
like image 178
Chris L Avatar answered Sep 30 '22 02:09

Chris L


Change the post action method like below:

[HttpPost]
public ViewResult Create(FormCollection formValues)
{
       var productId = formValues["productId"];
}

OR

[HttpPost]
public ViewResult Create(int  productId, FormCollection formValues)
{
 //still using productId, formValues is just an additional parameter 
 //that doesn't need to be implemented.
}
like image 23
Lin Avatar answered Sep 30 '22 01:09

Lin