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){...}
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){...}
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
Consider changing your signatures:
public ActionResult SelectInstitutionToEdit(){...}
public ActionResult SelectInstitutionToEditWithString(string message){...}
Although the compiler will run this code without any error because of method overloading but the MVC framework doesn't allow it. But you can use ActionName
attribute:
public ActionResult SelectInstitutionToEdit(){...}
[ActionName("SelectInstitutionToEditWithParams")]
public ActionResult SelectInstitutionToEdit(string message){...}
Then you should call it with it's new name. Like this:
@using (Html.BeginForm("SelectInstitutionToEditWithParams", "yourController"))
{
}
Use [ActionName("SomeOtherName")]
for the overloaded Action method if its the same get/post call.