Reputation: 8655
I am trying to create a form in my view that will route to a specific controller and action, that will do so as a Get request, and that will have a class attribute "pull-right"
This is what I've tried so far...
using (Html.BeginForm("LogOff", "Account", "Get", null, new {@class = "pull-right"}))
{
<div class="clearfix">
<label> In as: <strong>@User.Identity.Name</strong></label>
</div>
<button class="btn" type="submit">Log Out</button>
}
But it it is throwing an error and I can't figure out how to correctly create this method. Any help on this would be appreciated.
Upvotes: 1
Views: 2197
Reputation: 60468
The right overload of the BeginForm
method should, in your case, this
BeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName,
FormMethod method, object htmlAttributes);
Pass in the Get
using the enum FormMethod.Get
@using (Html.BeginForm("LogOff", "Account", FormMethod.Get, new {@class = "pull-right"}))
{
<div class="clearfix">
<label> In as: <strong>@User.Identity.Name</strong></label>
</div>
<button class="btn" type="submit">Log Out</button>
}
Upvotes: 5
Reputation: 4283
The third argument, FormMethod
, does not take a string, but an enum. Try FormMethod.Get
.
Upvotes: 1