2

I have a MasterPage, in my Views\Shared folder. I have an index.aspx in my Views\Home folder. And I have a login.ascx (user control) in my Views\User folder. The ascx file is added to my MasterPage:

<% Html.RenderPartial(@"~\Views\User\login.ascx");%>

The code in the ascx is pointing the submit form to a UserController.cs in my Controllers folder.

Here's the ascx:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BudgieMoneySite.Models.SiteUserLoginModel>" %>
<% using (Html.BeginForm("UserLogin", "User"))
   {%>
<table width="300">
    <tr>
        <td colspan="3" align="center">
            User Login
        </td>
    </tr>
    <tr>
        <td align="right">
            <%=Html.LabelFor(m => m.Username)%>
        </td>
        <td>
            <%=Html.TextBoxFor(m => m.Username)%>
        </td>
        <td>
        </td>
    </tr>
    <tr>
        <td align="right">
            <%=Html.LabelFor(m => m.Password)%>
        </td>
        <td>
            <%=Html.PasswordFor(m => m.Password)%>
        </td>
        <td>
        </td>
    </tr>
    <tr>
        <td>
        </td>
        <td>
            <%=Html.CheckBoxFor(m => m.RemeberMe)%><%=Html.LabelFor(m => m.RemeberMe)%>
        </td>
    </tr>
    <tr>
        <td colspan="2">
        </td>
        <td colspan="3" align="right">
            <input id="Submit1" type="submit" runat="server" value="Login" />
        </td>
    </tr>
</table>
<%
   } // End Using.%>

If I ctrl+click the Controller name and the method, in the Html.BeginForm area, it takes me to my method that should be called when I click Sybmit.

The method that this should call, in my UserController, has this code defined:

        [HttpPost]
    public ActionResult UserLogin(SiteUserLoginModel model)
    {
        try
        {
            if (MembershipService.ValidateUser(model.Username, model.Password))
            {
                FormService.SignIn(model.Username, model.RemeberMe);
                PersonDto  user = SiteUserLoginModel.LoadLoggedInUserDetails(model.Username);
                Session.Add("current_firstname", user.Firstname);
                Session.Add("current_userid", user.PersonId);
            }
            return RedirectToAction("Index", "Home");
        }
        catch (ArgumentException e)
        {
            ViewData["ErrorMessage"] = e.Message;
            return RedirectToAction("Index", "Home");
        }
    }

However, when I click the submit button at runtime, this method is never called. The screen just refreshed. The HomeController does fire though, as the index screen is refreshed, I think. But the breakpoint in my method above never fires.

What am I doing wrong?

1
  • Can you post what the form html tag looks like when it's generated and also what the submit button html looks like? Commented Jan 13, 2011 at 0:43

3 Answers 3

2

Your form in BeginForm isn't set to POST.

Try this: Html.BeginForm("UserLogin", "User", FormMethod.Post).

Sign up to request clarification or add additional context in comments.

1 Comment

mvc forms are POST by default.
1

I would start removing the runat="server" attribute from your submit button...

<input id="Submit1" type="submit" value="Login" />

Comments

1

Guys, I found the issue, and it's an issue I had 2 weeks back, but totoally forgot. The master page had a Form tag! And the user control's Form tage was being hidden by the master page's one. I remove the Form tags from the master page, and it's resolved.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.