【问题标题】:MVC Html.BeginForm using AreasMVC Html.BeginForm 使用区域
【发布时间】:2011-03-12 15:46:20
【问题描述】:

我正在使用 MVC 区域,并且在一个名为“测试”的区域中的视图上,我想要一个发布到以下方法的表单:

area: Security
controller: AccountController
method: logon

如何使用 Html.BeginForm 实现这一点?可以吗?

【问题讨论】:

    标签: asp.net-mvc html-helper


    【解决方案1】:

    对于那些想知道如何让它与默认 mvc4 模板一起工作的人

    @using (Html.BeginForm("LogOff", "Account", new { area = ""}, FormMethod.Post, new { id = "logoutForm" }))
    

    【讨论】:

    • +1 用于带有 'area' 的 additional 匿名类型,而不是像我尝试过的那样,将 'area' 添加到带有 'id' 的匿名类型中。
    【解决方案2】:

    试试这个:

    Html.BeginForm("logon", "Account", new {area="Security"})
    

    【讨论】:

      【解决方案3】:

      尝试将区域、控制器、动作指定为 RouteValues

      @using (Html.BeginForm( new { area = "security", controller = "account", action = "logon" } ))
      {
         ...
      }
      

      【讨论】:

        【解决方案4】:

        将此用于具有 HTML 属性的区域

        @using (Html.BeginForm(
              "Course", 
              "Assign", 
              new { area = "School" }, 
              FormMethod.Get, 
              new { @class = "form_section", id = "form_course" })) 
        {
        
           ...
        
        }
        

        【讨论】:

          【解决方案5】:
          @using (Html.BeginForm("", "", FormMethod.Post, new { id = "logoutForm", action = "/Account/LogOff" }))
                          {@Html.AntiForgeryToken()
                              <a class="signout" href="javascript:document.getElementById('logoutForm').submit()">logout</a>
                          }
          

          【讨论】:

            【解决方案6】:

            对于 Ajax BeginForm 我们可以使用这个

            Ajax.BeginForm("IndexSearch", "Upload", new { area = "CapacityPlan" }, new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, UpdateTargetId = updateTarget }, new { id = "search-form", role = "search" })
            

            【讨论】:

              猜你喜欢
              • 2014-12-02
              • 2013-06-02
              • 1970-01-01
              • 2014-06-18
              • 2010-11-03
              • 1970-01-01
              • 1970-01-01
              • 2020-06-04
              • 1970-01-01
              相关资源
              最近更新 更多