Reputation:
This is two action method in controller with same name, i want to change this action name using attribute.
[HttpGet]
public ActionResult Show()
{
return View();
}
[HttpPost]
public ActionResult Show(FormCollection frm)
{
return View();
}
Upvotes: 5
Views: 12506
Reputation: 458
You can use ActionName attribute.
[HttpPost, ActionName("Show")]
public ActionResult PostShow()
{
// your code...
}
Upvotes: 21
Reputation: 218952
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.
Upvotes: 2