Nikunj B. Balar
Nikunj B. Balar

Reputation: 298

Asp.net MVC: Multiple areas having same controller and action method - Html.BeginForm with Post action

I'm using areas feature of Asp.net MVC.

Two different areas with same name controllers:

Two area with same controller name

AdminAreaRegistration.cs enter image description here

UserAreaRegistration.cs enter image description here

I would like to have a form that posts to the following method:

 @using (Html.BeginForm("UserLogin", "Login", 
 new { area = "", model = this.Model, returnUrl = Request.QueryString["returnUrl"] },      
 FormMethod.Post, new { @Id = "frmLogin" }))

But i got an error:

enter image description here

How can i solve it with multiple areas have same name controller and post method using Html.BeginForm()?

Upvotes: 0

Views: 1243

Answers (1)

Aravindan
Aravindan

Reputation: 855

You have to define the area in the HTML helper tag as below

your area name must be defined in the HTML helper.

@using (Html.BeginForm("UserLogin", "Login", 
new { area = "YOUR AREA NAME", model = this.Model, returnUrl = Request.QueryString["returnUrl"] },      
FormMethod.Post, new { @Id = "frmLogin" }))

Upvotes: 1

Related Questions