1

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.

2
  • is it throwing error when you click the button or on load of the page? What is the error? Commented Jan 10, 2012 at 21:30
  • 1
    "it is throwing an error" is useless if you don't tell what the error is. Commented Jan 10, 2012 at 21:31

2 Answers 2

5

Description

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

Sample

 @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>
 }

More Information

Sign up to request clarification or add additional context in comments.

Comments

1

The third argument, FormMethod, does not take a string, but an enum. Try FormMethod.Get.

2 Comments

@dknaack Ah - I see it. The extra argument +1
Unfortunately i am over the 200 reputation (upvote) per day limit ;) Thanks anyway. Have a nice day!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.