9

Does ASP.NET MVC have any constants for the the strings "GET" and "POST"?

Daniel Vassallo
  • 337,827
  • 72
  • 505
  • 443
JoelFan
  • 37,465
  • 35
  • 132
  • 205
  • Wouldn't that be a little redundant? Descriptive string literals are basically constants on their own. – Karmic Coder Dec 28 '09 at 15:59
  • 4
    Where are you looking to use them? Typically it's better to make use of `HttpVerbs.Get` and `HttpVerbs.Post` – Agent_9191 Dec 28 '09 at 16:00
  • 1
    In which context? `AcceptVerbs`? `Html.BeginForm`? What are you trying to do? – Craig Stuntz Dec 28 '09 at 16:00
  • Comparing with HttpContext.Request.HttpMethod requires a string. Also the array parameter of AcceptVerbs requires strings. – JoelFan Dec 28 '09 at 23:17
  • Thats not true, check out http://stackoverflow.com/questions/283209/asp-net-mvc-acceptverbs-and-registering-routes, hence why they made the HttpVerbs enumeration in the MVC namespace. – Nick Larsen Dec 29 '09 at 13:59
  • Yes it is true... read what I said carefully... "the ARRAY parameter of AccetpVerbs requires strings"... I want to accept more than one verb... there is no way to do that with HttpVerbs. – JoelFan Dec 29 '09 at 14:41
  • 1
    Yes you can. HttpVerbs is a bit flag enumeration, if you want to accept more than 1 type you just have to OR them together, `[AcceptVerbs(HttpVerbs.GET | HttpVerbs.POST)]`, regardless if you want to use strings, you are correct that my answer is not the solution you asked for. – Nick Larsen Dec 30 '09 at 14:07
  • Wow, that is cool... I will switch to using that bit flag enumeration for AcceptVerbs. Thanks! However I still need the string to compare with HttpContext.Request.HttpMethod – JoelFan Dec 30 '09 at 17:23

2 Answers2

12

You can also use the System.Net.WebRequestMethods.Http class. (WebRequestMethods.Http.Get and WebRequestMethods.Http.Post)

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
7

Yes HttpVerbs.

http://msdn.microsoft.com/en-us/library/system.web.mvc.httpverbs(VS.100).aspx

Nick Larsen
  • 18,631
  • 6
  • 67
  • 96