MVC Html.BeginForm using Areas
asp.net MvcHtml Helperasp.net Mvc Problem Overview
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?
asp.net Mvc Solutions
Solution 1 - asp.net Mvc
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" }))
Solution 2 - asp.net Mvc
Try this:
Html.BeginForm("logon", "Account", new {area="Security"})
Solution 3 - asp.net Mvc
Try specifying the area, controller, action as RouteValues
@using (Html.BeginForm( new { area = "security", controller = "account", action = "logon" } ))
{
...
}
Solution 4 - asp.net Mvc
Use this for area with HTML Attributes
@using (Html.BeginForm(
"Course",
"Assign",
new { area = "School" },
FormMethod.Get,
new { @class = "form_section", id = "form_course" }))
{
...
}
Solution 5 - asp.net Mvc
@using (Html.BeginForm("", "", FormMethod.Post, new { id = "logoutForm", action = "/Account/LogOff" }))
{@Html.AntiForgeryToken()
<a class="signout" href="javascript:document.getElementById('logoutForm').submit()">logout</a>
}
Solution 6 - asp.net Mvc
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" })