Copied to clipboard

Flag this post as spam?

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


  • Nazar 3 posts 23 karma points
    Jan 16, 2014 @ 13:36
    Nazar
    0

    Problems with Html.BeginUmbracoForm

    I'm creating a mvc login form for existing Umbraco site I'm using Html.BeginUmbracoForm on the View, SurfaceController is called, but it fires "Can only use UmbracoPageResult in the context of an Http POST when using a SurfaceController form" exception

    My SurfaceController:
     [HttpGet]
            [ActionName("MemberLogin")]
            public ActionResult MemberLoginGet()
            {
                return View("MemberLogin", new MemberLoginModel());
            }
    
            // The MemberLogout Action signs out the user and redirects to the site home page:
    
        [HttpGet]
        public ActionResult MemberLogout()
        {
            Session.Clear();
            FormsAuthentication.SignOut();
            return Redirect("/");
        }
    
        [HttpPost]
        [ActionName("MemberLoginPost")]
        public ActionResult MemberLoginPost(MemberLoginModel model)
        {
            if (ModelState.IsValid && !MembersManager.IsMemberSponsor(model.Username))
            {
                result = MembersManager.AuthenticateUser(model.Username, model.Password);
                if (result.IsAuthenticated)
                {
                    model.Username = MembersManager.GetActualLoginString(model.Username);
                    FormsAuthentication.SetAuthCookie(model.Username, model.RememberMe);
                    return RedirectToUmbracoPage(32684);
                }
                else
                {
                    return View("MemberLogin");
                }
            }
            else
            {
                return CurrentUmbracoPage();
            }
        }
    

    And the View:

    @if (!User.Identity.IsAuthenticated)
    {
        using (Html.BeginUmbracoForm<Controllers.MemberLoginSurfaceController>("MemberLoginPost",  FormMethod.Post, new { action = this.Url.Action("MemberLoginPost","MemberLoginSurface") }))
        {
            <div id="wrapper">
                <div class="form-auth">
                    <ul class="auth">
                        <li>
                            <label>
                                E-mail</label>
                            @Html.TextBoxFor(x => x.Username)
                            @Html.ValidationMessageFor(x => x.Username)
                        </li>
                        <li>
                            <label>
                                Пароль</label>
                            <span class="input-block">
                                @Html.PasswordFor(x => x.Password)
                                @Html.ValidationMessageFor(x => x.Password)
                        </li>
                    </ul>
                    <div class="remember">
                        @Html.CheckBoxFor(x => x.RememberMe)
                        <label>
                            Запомнить</label>
                    </div>
                    <div class="submit">
                        <input type="submit" runat="server" id="usLoginButton" value="Войти"/>
                    </div>
                </div>
            </div>
        }
    }
    

    What should I do?

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Jan 16, 2014 @ 21:50
    Andy Butland
    0

    I think it might be your line: returnView("MemberLogin");

    Try changing that to returnCurrentUmbracoPage();

    Andy


  • Charles Afford 1163 posts 1709 karma points
    Jan 19, 2014 @ 12:55
    Charles Afford
    0

    Are you in the context of a partial view when you post to the controller?  If so you need to return a partial view.

    You also need to pass a new instance of MemberLoginModel into the View("MemberLogin)

    Charlie :)

Please Sign in or register to post replies

Write your reply to:

Draft