You cannot have multiple actions with the same name. You can add a parameter to one method and this will be valid. For example:
public ActionResult Index(int i) { Some Code--Some Code---Some Code return View(); }
There are several ways to do actions that differ only in the request verb. My favorite and, I think, the easiest way to use the AttributeRouting package. After installation, simply add the attribute to your method as follows:
[GET("Resources")] public ActionResult Index() { return View(); } [POST("Resources")] public ActionResult Create() { return RedirectToAction("Index"); }
In the above example, the methods have different names, but the action name in both cases is βResourcesβ. The only difference is the request verb.
The package can be installed using NuGet as follows:
PM> Install-Package AttributeRouting
If you do not need dependency on AttributeRouting packages, you can do this by writing a special attribute for the action selector.
Mark Mar 04 '12 at 7:05 2012-03-04 07:05
source share