Reputation: 603
I'm using MVC areas and on a view that's in an area called "Test" I would like to have a form that posts to the following method:
area: Security
controller: AccountController
method: logon
How can I make this happen with Html.BeginForm? Can it be done?
Upvotes: 55
Views: 37426
Reputation: 663
For Ajax BeginForm we can use this
Ajax.BeginForm("IndexSearch", "Upload", new { area = "CapacityPlan" }, new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, UpdateTargetId = updateTarget }, new { id = "search-form", role = "search" })
Upvotes: 2
Reputation: 1698
For those of you that want to know how to get it to work with the default mvc4 template
@using (Html.BeginForm("LogOff", "Account", new { area = ""}, FormMethod.Post, new { id = "logoutForm" }))
Upvotes: 96
Reputation: 4223
@using (Html.BeginForm("", "", FormMethod.Post, new { id = "logoutForm", action = "/Account/LogOff" }))
{@Html.AntiForgeryToken()
<a class="signout" href="javascript:document.getElementById('logoutForm').submit()">logout</a>
}
Upvotes: 3
Reputation: 1111
Use this for area with HTML Attributes
@using (Html.BeginForm(
"Course",
"Assign",
new { area = "School" },
FormMethod.Get,
new { @class = "form_section", id = "form_course" }))
{
...
}
Upvotes: 5
Reputation: 1136
Try this:
Html.BeginForm("logon", "Account", new {area="Security"})
Upvotes: 86
Reputation: 532435
Try specifying the area, controller, action as RouteValues
@using (Html.BeginForm( new { area = "security", controller = "account", action = "logon" } ))
{
...
}
Upvotes: 7