Can we change Action Method name in ASP.NET MVC Application?
Solution 1:
You can use ActionName attribute.
[HttpPost, ActionName("Show")]
public ActionResult PostShow()
{
// your code...
}
Solution 2:
You can have the same name, but make sure that the method signature is different. To do that, you can simply add a parameter to your post method.
[HttpGet]
public ActionResult Show()
{
return View();
}
[HttpPost]
public ActionResult Show(string name)
{
return View();
}
Now when the Show form is submitted the input field with name value name
will be submitted to the HttpPost action method.