Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set FormMethod.Get with Html.BeginForm

Tags:

asp.net-mvc

I would like to have my form do a Get rather than a Post (It's a query field the user is submitting)

I know I can do it with

<% using(Html.BeginForm(action, controller, FormMethod.Get) {%>

However, I would rather not have to specify the action/Controller and there doesn't seem to be an overload that takes FormMethod only.

This is MVC 1.0 (and without the futures)

like image 325
Ralph Shillington Avatar asked Jan 23 '23 14:01

Ralph Shillington


1 Answers

There is no such overload in the framework. However, if you send in action and controller as null the framework will do what you want. If you don't like that you can create that extension yourself:

public static MvcForm BeginForm(this HtmlHelper htmlHelper, FormMethod method) {
    return htmlHelper.BeginForm(null, null, method);
}
like image 83
Mattias Jakobsson Avatar answered Feb 04 '23 22:02

Mattias Jakobsson