Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC Html.BeginForm using Areas

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?

like image 759
Mariko Avatar asked Mar 12 '11 15:03

Mariko


People also ask

What is the use of HTML BeginForm in MVC?

Html. BeginForm is the Html Helper Extension Method that is used for creating and rendering the form in HTML. This method makes your job easier in creating form. Here, is the method to create a form using Html.

What is the use of @using HTML BeginForm ())?

BeginForm(HtmlHelper, String, String, FormMethod) Writes an opening <form> tag to the response and sets the action tag to the specified controller and action. The form uses the specified HTTP method.

What is difference between HTML BeginForm and Ajax BeginForm?

BeginForm() will create a form on the page that submits its values to the server as a synchronous HTTP request, refreshing the entire page in the process. Ajax. BeginForm() creates a form that submits its values using an asynchronous ajax request.

What is HTML ActionLink in MVC?

Html. ActionLink creates a hyperlink on a view page and the user clicks it to navigate to a new URL. It does not link to a view directly, rather it links to a controller's action.

What is HTML beginform in MVC?

What is Html.BeginForm? What is Html.BeginForm? Html.BeginForm is the Html Helper Extension Method that is used for creating and rendering the form in HTML. This method makes your job easier in creating form. Here, is the method to create a form using Html.BeginForm extension method in ASP.NET MVC5.

How to generate HTML form tag in MVC Razor?

The Html.BeginForm extension method is used to generate an HTML Form Tag in ASP.Net MVC Razor. In this article I will explain a simple tutorial with example on how to use Html.BeginForm extension method in ASP.Net MVC Razor. The Html.BeginForm extension method is used to generate an HTML Form Tag in ASP.Net MVC Razor.

What is the use of area in MVC?

Areas are an ASP.NET MVC feature used to organize related functionality into a group as a separate namespace (for routing) and folder structure (for views). Using areas creates a hierarchy for the purpose of routing by adding another route parameter, area, to controller and action.

What is the use of beginform in Ajax?

BeginForm is an extension method of @HtmlHelper class and used for creating, rendering the form tag in HTML. For more detail visit this link. BeginForm is an extension method of @AjaxHelper classes and used for creating, rendering the form tag in HTML. @Ajax.BeginForm Helper method submits the form asynchronously using JavaScript.


6 Answers

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" }))
like image 170
mosesfetters Avatar answered Oct 21 '22 14:10

mosesfetters


Try this:

Html.BeginForm("logon", "Account", new {area="Security"})
like image 31
Nam Le Avatar answered Oct 21 '22 12:10

Nam Le


Try specifying the area, controller, action as RouteValues

@using (Html.BeginForm( new { area = "security", controller = "account", action = "logon" } ))
{
   ...
}
like image 37
tvanfosson Avatar answered Oct 21 '22 13:10

tvanfosson


Use this for area with HTML Attributes

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

   ...

}
like image 40
SamJackSon Avatar answered Oct 21 '22 12:10

SamJackSon


@using (Html.BeginForm("", "", FormMethod.Post, new { id = "logoutForm", action = "/Account/LogOff" }))
                {@Html.AntiForgeryToken()
                    <a class="signout" href="javascript:document.getElementById('logoutForm').submit()">logout</a>
                }
like image 39
Mohammad Karimi Avatar answered Oct 21 '22 13:10

Mohammad Karimi


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" })
like image 29
Sumesh Es Avatar answered Oct 21 '22 12:10

Sumesh Es