Reputation: 63
I have two Areas
: Profile
(for every user) and Admin
(for admins). Some users can have Companies and manage them in their profile, and Admins can also create Companies in their area.
In the Admin area I have a "_BaseForm"
file where I keep common code and call different partials to fill the form with fields, something like :-
var content = string.Format("~/Areas/Admin/Views/{0}/_Form.cshtml", (string)ViewBag.FolderName);
@using (Html.BeginForm(null,null,FormMethod.Post,new { @enctype = "multipart/form-data" }))
{
@Html.Partial(content)
}
The problem is that when I call the Add()
function that returns the View, it gets the correct form, but the action URL corresponds to the controller/action of the Profile Area
:-
<form action="/Profile/Companies/Add" ..> <!-- it should be "/Admin/Companies/Add" -->
When I comment the Add (Company)
functions in the Profile
area, it works properly.
Can you help me?
Thank you
Upvotes: 0
Views: 2022
Reputation: 18873
Just correct your BeginForm as :
@using (Html.BeginForm(null,null,new{ area="Admin" },FormMethod.Post,new { @enctype = "multipart/form-data" }))
{}
Upvotes: 1