2011-03-12 86 views
43

我使用MVC領域和那是在所謂的「測試」一區一景,我想有一個表單的帖子下面的方法:MVC Html.BeginForm使用領域

area: Security 
controller: AccountController 
method: logon 

哪有我用Html.BeginForm做到這一點?可以做到嗎?

回答

68

試試這個:

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

嘗試指定的區域,控制器,行動RouteValues

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

對於那些你想知道如何得到它使用默認mvc4模板工作

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

+1爲*額外*匿名類型與「區域」,而不是增加「區域」,可以匿名類型與「ID」,因爲我試過。 – Jeff 2013-12-31 00:05:48

3

使用此與HTML的區域屬性

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

    ... 

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