views:

42

answers:

1

Hi All, All im trying to do is create a login control that i want to place within my home page.

Ive created a Login User Control as follows:

<%@ Control Language="VB" Inherits="System.Web.Mvc.ViewUserControl(Of MyWebsite.LogOnModel)" %>
<% Using Html.BeginForm() %>
    <%: Html.ValidationSummary(True, "Login was unsuccessful. Please correct the errors and try again.")%>
    <div>

            <div class="editor-label">
                <%: Html.LabelFor(Function(m) m.UserName) %>
            </div>
            <div class="editor-field">
                <%: Html.TextBoxFor(Function(m) m.UserName) %>
                <%: Html.ValidationMessageFor(Function(m) m.UserName) %>
            </div>

            <div class="editor-label">
                <%: Html.LabelFor(Function(m) m.Password) %>
            </div>
            <div class="editor-field">
                <%: Html.PasswordFor(Function(m) m.Password) %>
                <%: Html.ValidationMessageFor(Function(m) m.Password) %>
            </div>

            <div class="editor-label">
                <%: Html.CheckBoxFor(Function(m) m.RememberMe) %>
                <%: Html.LabelFor(Function(m) m.RememberMe) %>
            </div>
            <p>
                <input type="submit" value="Log On"  />
            </p>

    </div>
<% End Using %>

I than rendered this on the home index.aspx page:

Html.RenderPartial("UsrCtlLogin")

It shows up correctly on the home page. But my question is how do i hook it up to the AccountController logic. i.e. On click of login i want it to fire the LogOn http method and validate the user (show invalid message if invalid details are supplied) and than redirect them to a page if they are successful.

How do i create the link between the user control and the AccountController?

Thanks in advance

+2  A: 

By default the form will post to the current uri. So if this is your home page, you can create a method in your home controller:

[HttpPost]
public ActionResult Index() {
     //authenticate
     return View();
}

But you don't really want to mix controller responsibilities. So change your forms action to post to /users/login or whatever post method you want in your AccountController.

using (Html.BeginForm("Login", "Account", FormMethod.Post))
Bigfellahull