Send "@ Html.BeginForm" to controller from another area. Asp.Net

5

I have a controller in a Area named " LoginProfessional ", with actions Index, Logon, Logoff . I make a RenderPage by calling Index in the Area root of the project, however when I click the button it is to send the form to the controller Home of area LoginForm it sends to Home da Root , this file is within the controllers directory of Login , however rendered in Root which has a controller named Home as well. Here is the code:

Login index (within the folder area LoginProfessional ):

@{
    ViewBag.Title = "Login";
}

<div class="container row" style="width: 30%; margin-left: auto; margin-right: auto">
    @using (Html.BeginForm("Logon", "Home", FormMethod.Post))
    {
        <form class="center-block form-signin" role="form" style="width: 30%; align-content: center">
            <div class="form-group">
                <input type="text" id="email" class="form-control" name="email" placeholder="E-mail" required="required" autocomplete="on">
                <input type="password" id="password" class="form-control" name="password" placeholder="Senha" required="required" autocomplete="off">
                <button class="btn btn-lg btn-primary btn-block" type="submit">Entrar</button>

                <nav class="mainmenu pull-right" style="width: 246px; margin: auto; position: relative; max-width: 100%;">
                    <span class="pull-right">
                        <a class="btn btn-default btn-small" href="#registerProfessionalUser">Registrar</a>
                    </span>
                </nav>
            </div>
        </form>
    }
</div>

Location in _Layout.cshtml where you render this page in the project root (outside the areas):

<section class="section" id="professional">
        <div class="container">
            <h2 class="text-center title">Profissional</h2>
            @RenderPage("~/Areas/LoginProfessional/Views/Home/Index.cshtml")

Correct controller within the LoginProfessional area:

 public class HomeController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult Logon(FormCollection form)
        {
            if (ModelState.IsValid)
            {
                ProfessionalUser pUser = new ProfessionalUser();
                using (LoginProfessionalDAO dao = new LoginProfessionalDAO())
                {
                    pUser = dao.GetProfessionalUserByEmailAndPassword(form["email"].ToString(), form["password"].ToString());
                }

                if (pUser != null)
                {
                    FormsAuthentication.SetAuthCookie(pUser.Name, false);
                    return Redirect("../../ProfessionalUser");
                }
            }
            return RedirectToAction("Index", "Home");
        }

        public ActionResult Logoff()
        {
            FormsAuthentication.SignOut();
            return RedirectToAction("Index", "Home");
        }
    }

I need to stop calling Logon do Home within the LoginProfessional area, not the root, since it does not even exist.

    
asked by anonymous 15.05.2014 / 19:11

1 answer

2

I solved the problem by setting the name of the controller inside the Area LoginProfessional, since it was the same name as it had outside (the two were HOME), there was confusion in deploy, not forgetting to also adjust the namespaces of the controller.

    
15.05.2014 / 21:21