views:

19

answers:

1

Hi, This is a follow on from: http://stackoverflow.com/questions/3605689/mvc-partial-login-control

I got the AccountController Logon Post event firing from my child control. The problem I have now is that when a user enters an incorrect password the AccountController Logon post tries to return to the Logon.aspx page not my Logon partial control. This is the code from the controller:

<HttpPost()> _
Public Function LogOn(ByVal model As LogOnModel, ByVal returnUrl As String) As ActionResult
    If ModelState.IsValid Then
        If MembershipService.ValidateUser(model.UserName, model.Password) Then
            FormsService.SignIn(model.UserName, model.RememberMe)
            If Not String.IsNullOrEmpty(returnUrl) Then
                Return Redirect(returnUrl)
            Else
                Return RedirectToAction("Index", "Home")
            End If
        Else
            ModelState.AddModelError("", "The user name or password provided is incorrect.")
        End If
    End If

    ' If we got this far, something failed, redisplay form
    Return View(model)
End Function

Im passing the returnUrl in so if the user enters the correct details it works perfectly. But all i want it to do is if they enter the wrong details is to show "The User Name or Password provided is incorrect" on my child control.

Any ideas?

Thanks

A: 

MVC automatically looks for a view with the same name as the controller action, But i don't think it looks for a partial view (i could be wrong).

try this:

return PartialView(model)

If the partial view name is not the same as the controller action you will have to specify the partialview name explicitly

return PartialView("PartialViewName",model)

Am i right in thinking the partial view is only if they enter the incorrect details? If so, you could save yourself a lot of hassle by using the System.ComponentModel.DataAnnotations class, so that you can display your validation messages on the same logon form, so you don't have to build and maintain a partial view. If you already know about data annotations look into it, if not add a comment and i'll post some useful links that will explain it a lot better than i could.

Doozer1979
Hi Doozer, Thanks for your response. Basically my partial (usercontrol) login control sits on my home page (Html.RenderPartial("UsrCtlLogin")). When the user logs in I want it to than redirect it to their profile page. If they provide incorrect details than i want it to stay on the home page and just show a message within the login partial control saying incorrect details...I tried your return PartialView("UsrCtlLogin", model) suggestion but it just redirected to the PartialView by itself (partialview now takes up the entire page).Any ideas?
Raven
Maybe i'm not getting this correctly (it is 1am after all:)), but in the logon.aspx page is there not a <% Html.RenderPartial("Logon"); %>
Doozer1979
By the look of your previous question you've already got a validation summary message in your view, so technically you don't need to provide one in your controller. Have you come across the dataannotations class yet? It really does save a lot of hassle....
Doozer1979