Send "@Html.Beginform" to another area controller. Asp.Net

Asked

Viewed 1,220 times

5

I own a controller in a Area calling for "LoginProfessional", with the actions Index, Logon, Logoff. I make a RenderPage calling for the Index in Area root of the project, but when I click on the button to send the form to the controller Home of area LoginForm he sends to the Home da Root, this file is inside the directory of controllers of Login, but rendered in Root who owns a controller called Home also. The code below:

Login Index (inside 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 at the root of the project (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 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 the Logon do Home within the area LoginProfessional, not the root, because it doesn’t even exist.

1 answer

2

I solved the problem by setting the controller name inside the Area Loginprofessional, as it was the same name as what it had outside (the two were HOME) was happening confusion in the deploy, not forgetting to also adjust the namespaces controller’s.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.