physics90 physics90 - 1 month ago 5
C# Question

Two Actions in Controler with Different Parameter Settings Conflict

I have two methods (Actions) with different option formats but when I run it I'm told they are ambiguous. Methods shown below.

public ActionResult SelectInstitutionToEdit(){...}
public ActionResult SelectInstitutionToEdit(string message){...}

Answer

Yes. You cannot have more than one action method with same name (& same http verb).

If you want both to work for Http GET requests, you may keep the second one, and check the value of your message parameter and based on that return the relevant response.

public ActionResult SelectInstitutionToEdit(string message)
{
  if(String.IsNullOrEmpty(message))
  {
    // to do :Return something
  }
  // to do :Return something
}

This will work for yourSite/yourController/SelectInstitutionToEdit and yourSite/yourController/SelectInstitutionToEdit?message=hello