ASP.NET MVC3使用具有特定属性的HTML.BeginForm创建表单元素

jda*_*vis 1 asp.net-mvc-3

我正在尝试在我的视图中创建一个表单,该表单将路由到特定的控制器和操作,这将作为Get请求执行,并且将具有类属性"pull-right"

这是我到目前为止所尝试的......

 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>
 }
Run Code Online (Sandbox Code Playgroud)

但它正在抛出错误,我无法弄清楚如何正确创建此方法.任何有关这方面的帮助将不胜感激.

dkn*_*ack 5

描述

BeginForm在您的情况下,该方法的正确重载应该是这样

  BeginForm(this HtmlHelper htmlHelper, string actionName, string controllerName, 
            FormMethod method, object htmlAttributes);
Run Code Online (Sandbox Code Playgroud)

传递Get使用枚举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>
 }
Run Code Online (Sandbox Code Playgroud)

更多信息