Saturday, September 18, 2010

How to create HTTP POST and GET methods with the same signature

When using Ajax Uploader (a very cool component) and MVC, I ran into a situation where I needed the same signature for the HTTP GET and HTTP POST controller actions. The compiler wouldn't let me use the same name. The ActionName attribute solved that problem.


[ActionName( "UploadArtwork" )]
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult UploadArtworkGet(string dataMyComponentUses)
{
...
return View( "UploadArtwork" );
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UploadArtwork(string dataMyComponentUses)
{
...
return View( "UploadArtwork" );
}

No comments:

Post a Comment