7

I have an MVC3 C#.NET web app and need to call a view using Html.ActionLink. I can't tell from the documentation if I can specify the POST or GET. Below is my HTML, is there a way to specify GET or POST?

 @Html.ActionLink("Create New", "Edit", "Subtask", 
                        new {Id = ViewBag.Id, Command="CreateHourEntry"}, null)
vcsjones
  • 133,702
  • 30
  • 291
  • 279
MikeTWebb
  • 8,831
  • 25
  • 90
  • 131

3 Answers3

7

If you want a post use Ajax.ActionLink but be aware it's an Ajax post. You could easily use jquery to cause your existing link to cause a form post but this functionality is not included in Html.ActionLink.

See ASP.NET MVC ActionLink and post method

Community
  • 1
  • 1
Adam Tuliper
  • 29,829
  • 4
  • 51
  • 70
6

HTML hyperlinks send GETs.

To POST, you need to use a form.
or some Javascript

SLaks
  • 837,282
  • 173
  • 1,862
  • 1,933
3

You can also use Ajax.ActionLink where you can specify POST or GET

@Ajax.ActionLink("Create New", "Edit", "Subtask",
                  new AjaxOptions{ HttpMethod="Post"}) 
Shivkumar
  • 1,893
  • 5
  • 21
  • 32