I have a controller with a postback action:
[HttpPost]
public ActionResult test(string x) { ... }
and I wanted to add a GET action with the same signature:
public ActionResult test(string y) { ... }
but the compiler pukes:
Type 'TestController' already defines a member called 'test' with
the same parameter types
so I thought to change the signature:
public ActionResult test(RouteValueDictionary args) { ... }
and call it like this:
@{
RouteValueDictionary args = new RouteValueDictionary(
new { y = "test" }
);
}
@Html.Action("test", "TestController", args)
but the controller receives args as null. clearly I don’t get how this is supposed to work. I know I could just rename the action but I’d like to know how to declare it such that my dictionary comes across.
TIA – e
You can keep the signature and just change the name of the method, but use the same action name by specifying the
ActionNameAttribute.For example
The method names are different, but the MVC action is the same for both: “Foo”.