Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Wilson 14 posts 103 karma points
    Aug 06, 2017 @ 08:13
    Wilson
    0

    show message in form when Login Failed

    Hi, i have below controller for user login:

        public ActionResult DoLogin(myLoginViewModels model)
        {
            if (ModelState.IsValid)
            {
                if (validateUserAccount(model))
                {
                    TempData["LoginSuccess"] = true;
                    FormsAuthentication.SetAuthCookie(model.User, false);
                    return RedirectToCurrentUmbracoPage();
                } 
                else
                {
                    TempData["Status"] = "Invalid Log-in Credentials";
                    TempData["LoginSuccess"] = false;
                    return CurrentUmbracoPage();
                    //return View(model);
                }
            }
            return CurrentUmbracoPage();
        }
    

    and i try to show TempData["Status"] in my form if login failed, but i don' know how to do this, below is my template :

    <div class="container">
        @if (TempData["LoginSuccess"] != null && (bool)TempData["LoginSuccess"])
        {
            Html.RenderAction("RenderForm", "myMember");
        }
        else
        {
            Html.RenderAction("RenderForm", "myLogin");
        }
    </div>
    
  • Alex Skrypnyk 6133 posts 23952 karma points MVP 7x admin c-trib
    Aug 07, 2017 @ 08:41
    Alex Skrypnyk
    0

    Hi Wilson

    What is the value of TempData["LoginSuccess"] if you debug?

    Thanks,

    Alex

  • Wilson 14 posts 103 karma points
    Aug 07, 2017 @ 10:10
    Wilson
    0

    refer to my controller, if validateUserAccount return true, it will execute

    TempData["LoginSuccess"] = true;

    and if false, TempData["LoginSuccess"] will never create and have null value.

    when come to Template,

    @if (TempData["LoginSuccess"] != null && (bool)TempData["LoginSuccess"])

    is working as expected and manage to RenderAction.

  • Paul Seal 524 posts 2889 karma points MVP 6x c-trib
    Aug 07, 2017 @ 10:28
    Paul Seal
    100

    Hi In this tutorial, I use the approach of adding a ModelError to the ModelState and returning the current Umbraco Page.

    That way the error will show in the validation summary

    http://www.codeshare.co.uk/blog/tutorial-how-to-create-member-login-and-logout-form-in-umbraco-mvc/

Please Sign in or register to post replies

Write your reply to:

Draft