I'm new to programming and specifically to C#/Asp.Net MVC and I've been trying for a while now to get this to work and i'm running out of ideas. I've tried to find the answer online but haven't come up with a solution yet (even after reading and trying the methods I found for similar questions). This forum is a little intimidating to posting new things but I'm stuck right now. So I figured I'd give it a shot.
I have this project I'm making in which i'm using bootstrap, asp.net and C# to create a webpage which will be an e-commerce-like site. Currently i'm working on the login system. I'm using SimpleMembership and trying to create a login form that does not need a new page solely for the Login, it's actually on a shared view.
Here's the view with the form for the login partial:
@model FakeStore.ViewModels.MenuSuperiorModel
<form class="navbar-form navbar-right">
@if (!WebSecurity.IsAuthenticated)
{
using (Html.BeginForm("Autentica", "Login", FormMethod.Post))
{
<div class="form-group">
@Html.TextBoxFor(m => m.login, new { @class="form-control", placeholder="Login" })
</div>
<div class="form-group">
@Html.TextBoxFor(m => m.senha, new { @class ="form-control", placeholder="Senha"})
</div>
@Html.HiddenFor(m => m.CarrinhoCount)
<input type="submit" value="Sign in" class="btn btn-success" />
<a class="btn btn-success" href="~/Usuario/Form">Register</a>
}
}
else if (WebSecurity.IsAuthenticated)
{
<span class="label label-primary">Welcome, @(WebSecurity.CurrentUserName)!</span>
}
</form>
That view is a child of another partial view which is on a layout page.
This is the Partial view that calls the Login Form view:
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
@Html.Partial("_CarrinhoCompraTopMenu")
<div id="navbar" class="navbar-collapse collapse">
<!-- vamos ver se dá problema esse _LoginMenu -->
@Html.Partial("_LoginMenu")
</div><!--/.navbar-collapse -->
</div>
</nav>
Here's the Controller with the Action the BeginForm's method should be calling:
public class LoginController : Controller
{
// GET: Login
private UsuarioDAO udao;
public LoginController(UsuarioDAO udao)
{
this.udao = udao;
if (!WebSecurity.Initialized)
{
WebSecurity.InitializeDatabaseConnection("StoneECommerce", "Usuario", "Id", "Login", true);
}
}
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Autentica(MenuSuperiorModel menuSuperiorModel)
{
if (WebSecurity.Login(menuSuperiorModel.login, menuSuperiorModel.senha))
{
return RedirectToAction("Form", "Produto");
}
else
ModelState.AddModelError("login.Invalido", "Login ou senha incorretos");
return View("Index");
}
public ActionResult LoginMenu()
{
return PartialView("_LoginMenu");
}
I'm trying to get the submit button to send the MenuSuperiorModel to the LoginController's action Autentica so that it can authenticate the user. But the thing is that it's not even getting to that action. I tried setting a breakpoint on it and the action isn't being called. Am I missing something? I really appreciate the help.
ps: I also have no custom routes configured.
You have nested forms which is invalid html and not supported. Remove the outer <form class="navbar-form navbar-right">
element.