title: MVC Calling another controllers action
body: <p>I have started an MVC project and it has created the AccountController Class for me.
  So to login to my current site I would have to go to, localhost:2500\Account.mvc\LogOn</p>
  
  <p>I wanted to make the login on my HomeController in the Index view. So basically if you go to my root of the site if not authenticated you would have to login to go anywhere else.</p>
  
  <p>So what I did was add the form to my Index View and tried to have it post to my
  Account view calling the LogOn action.</p>
  
  <p>I have called the BeginForm method passing it my action and the respective view (LogOn, Account). When I click the button, it doesn't post to the Account view therefore doesn't execute the LogOn action. Instead, it just posts to the Home view calling the Index action again. So it really does nothing for me... haha.</p>
  
  <p>Not sure what I am doing wrong. Below is my raw form code from Home/Index.aspx and then I also will show you the source after its rendered before hitting the logon button.</p>
  
  <p>Here's my code from Home/Index.aspx:</p>
  
  <pre><code>  &lt;% using (Html.BeginForm("LogOn", "Account")) { %&gt;
              &lt;div&gt;
                  &lt;fieldset&gt;
                      &lt;legend&gt;Account Information&lt;/legend&gt;
                      &lt;p&gt;
                          &lt;label for="username"&gt;Username:&lt;/label&gt;
                          &lt;%= Html.TextBox("username") %&gt;
                          &lt;%= Html.ValidationMessage("username") %&gt;
                      &lt;/p&gt;
                      &lt;p&gt;
                          &lt;label for="password"&gt;Password:&lt;/label&gt;
                          &lt;%= Html.Password("password") %&gt;
                          &lt;%= Html.ValidationMessage("password") %&gt;
                      &lt;/p&gt;
                      &lt;p&gt;
                          &lt;%= Html.CheckBox("rememberMe") %&gt; &lt;label class="inline" for="rememberMe"&gt;Remember me?&lt;/label&gt;
                      &lt;/p&gt;
                      &lt;p&gt;
                          &lt;input type="submit" value="Log On" /&gt;
                      &lt;/p&gt;
                  &lt;/fieldset&gt;
              &lt;/div&gt;
          &lt;% } %&gt;
  </code></pre>
  
  <p>View Source of Home.mvc/Index:</p>
  
  <pre><code>&lt;form action="/Account.mvc/LogOn" method="post"&gt;
      &lt;div&gt;
          &lt;fieldset&gt;
              &lt;legend&gt;Account Information&lt;/legend&gt;
              &lt;p&gt;
                  &lt;label for="username"&gt;Username:&lt;/label&gt;
                  &lt;input id="username" name="username" type="text" value="" /&gt;
  
              &lt;/p&gt;
  
              &lt;p&gt;
                  &lt;label for="password"&gt;Password:&lt;/label&gt;
                  &lt;input id="password" name="password" type="password" /&gt;
  
              &lt;/p&gt;
              &lt;p&gt;
                  &lt;input id="rememberMe" name="rememberMe" type="checkbox" value="true" /&gt;&lt;input name="rememberMe" type="hidden" value="false" /&gt; &lt;label class="inline" for="rememberMe"&gt;Remember me?&lt;/label&gt;
              &lt;/p&gt;
  
              &lt;p&gt;
                  &lt;input type="submit" value="Log On" /&gt;
              &lt;/p&gt;
          &lt;/fieldset&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>I set a break point at my LogOn action and it never gets hit, so its not a login error either.</p>
  
  <p>It looks like the action in the html source is set correctly, I just don't understand why it doesn't post correctly. I'm not doing something right. Please let me know if you have any ideas. Thanks!</p>
  
  <p>LogOn Action in the Account View:</p>
  
  <pre><code>[AcceptVerbs(HttpVerbs.Post)]
          [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings",
              Justification = "Needs to take same parameter type as Controller.Redirect()")]
          public virtual ActionResult LogOn(string userName, string password, bool rememberMe, string returnUrl)
          {
  
              if (!ValidateLogOn(userName, password))
              {
                  return View();
              }
  
              FormsAuth.SignIn(userName, rememberMe);
              if (!String.IsNullOrEmpty(returnUrl))
              {
                  return Redirect(returnUrl);
              }
              else
              {
                  return RedirectToAction("Index", "Home");
              }
          }
  </code></pre>