title: ASP.NET MVC 4 - Login on home page
body: <p>I want a login form on my home page. In <code>index.cshtml</code> I have this:</p>
  
  <pre><code>@using (Html.BeginForm("Login", "AccountController", FormMethod.Post)) {
      @Html.AntiForgeryToken()
      @Html.ValidationSummary(true)
          &lt;div&gt;
              &lt;div class="usernametb"&gt;
                  @Html.LabelFor(m =&gt; m.LoginMod.UserName)
              &lt;/div&gt;
              &lt;div class="usernametb"&gt;
                  @Html.TextBoxFor(m =&gt; m.LoginMod.UserName, new { style = "width:150px" })
                  @Html.ValidationMessageFor(m =&gt; m.LoginMod.UserName)
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="clear"&gt;&lt;/div&gt;
          &lt;div&gt;
              &lt;div class="pwtb"&gt;
                  @Html.LabelFor(m =&gt; m.LoginMod.Password)
              &lt;/div&gt;
              &lt;div class="pwtb"&gt;
                  @Html.PasswordFor(m =&gt; m.LoginMod.Password, new { style = "width:150px" })
                  @Html.ValidationMessageFor(m =&gt; m.LoginMod.Password)
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="clear"&gt;&lt;/div&gt;
          &lt;div class="rememberme"&gt;
              @Html.CheckBoxFor(m =&gt; m.LoginMod.RememberMe)
              @Html.LabelFor(m =&gt; m.LoginMod.RememberMe, new { @class = "checkbox" })
          &lt;/div&gt;
          &lt;div&gt;&lt;input class="loginbutton" type="submit" value="Log In" /&gt;&lt;/div&gt;
  }
  </code></pre>
  
  <p>I reference this model:</p>
  
  <pre><code>namespace memsite.Models
  {
      public class MemEvent
      {
          public LoginModel LoginMod { get; set; }
          public DateTime Start { get; set; }
          public DateTime End { get; set; }
          public string Name { get; set; }
          public string Description { get; set; }
      }
  }
  </code></pre>
  
  <p>I am trying to hit this account controller login action, but it never hits the controller, it just re-directs to <code>/AccountController/Login</code> which doesn't exist. Also, the validation controls are not working...</p>
  
  <pre><code>namespace memsite.Controllers
  {
      [Authorize]
      [InitializeSimpleMembership]
      public class AccountController : Controller
      {
          //
          // GET: /Account/Login
  
          [AllowAnonymous]
          public ActionResult Login(string returnUrl)
          {
              ViewBag.ReturnUrl = returnUrl;
              return View();
          }
  
          //
          // POST: /Account/Login
  
          [HttpPost]
          [AllowAnonymous]
          [ValidateAntiForgeryToken]
          public ActionResult Login(LoginModel model, string returnUrl)
          {
              if (ModelState.IsValid &amp;&amp; WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
              {
                  return RedirectToLocal(returnUrl);
              }
  
              // If we got this far, something failed, redisplay form
              ModelState.AddModelError("", "The user name or password provided is incorrect.");
              return View(model);
          }
  </code></pre>
  
  <p>(I am brand new to MVC having left webforms land forever.)</p>