0

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

5
  • ....@using (Html.BeginForm("Add","Companies",FormMethod.Post,new{ area="Admin" },new { @enctype = "multipart/form-data" })) Commented Aug 5, 2014 at 11:24
  • try above beginform... Commented Aug 5, 2014 at 11:25
  • thank you, but the thing is I want to keep Html.BeginForm(null,null, ..) so it can be used for other models Commented Aug 5, 2014 at 11:29
  • 1
    ok..then do it as...@using (Html.BeginForm(null,null,FormMethod.Post,new{ area="Admin" },new { @enctype = "multipart/form-data" })) Commented Aug 5, 2014 at 11:31
  • omg i didnt remember to do that! yes it worked thank you! :) (btw it had to be in a different order: Html.BeginForm(null,null,new { area = "Admin" },FormMethod.Post, new { @enctype = "multipart/form-data" }) Commented Aug 5, 2014 at 13:01

1 Answer 1

1

Just correct your BeginForm as :

@using (Html.BeginForm(null,null,new{ area="Admin" },FormMethod.Post,new { @enctype = "multipart/form-data" }))
{}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.