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 15, 2014 @ 15:37
    Nazar
    0

    Troubles using Html.BeginUmbracoForm

    I'd like to create a form that posts data to specific action in my SurfaceController
    But Html.BeginUmbracoForm creates a form that has action set to link to current View

    For example, I need form to post data  to LoginUserPost action and I get a LoginView by LoginUserGet action
    Html.BeginUmbracoForm creates a form on a page with action set to  LoginUserGet url. Why could this happen?

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

    I have a View:

    using (Html.BeginUmbracoForm<Controllers.MemberLoginSurfaceController>("MemberLoginPost", FormMethod.Post, new { action = this.Url.Action("MemberLoginPost", "MemberLoginSurface") }))

        {

            <div id="wrapper">

                <div class="form-auth" style="width:420px; height:195px; overflow:hidden;">

                    <a class="close" onclick="clearForm()"></a>

                    <div class="text" style="margin-left:0px;">

                        Вход для участников</div>

                    <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)

                            </span><a href="javascript:window.parent.showGeneralIFramePopup('/usercontrols/ForgotPassword.aspx', false, null);" class="remind">Забыли?</a> </li>

                    </ul>

                    <div class="remember">

                        @Html.CheckBoxFor(x => x.RememberMe)

                        <label>

                            Запомнить</label>

                    </div>

                    <div class="submit">

                        @*<asp:Button ID="usLoginButton" runat="server" Text="Войти" CommandName="Login" ValidationGroup="vgLoginUser" />*@

                        <input type="submit" id="usLoginButton" value="Войти"/>

                        <span>или</span> <a href="javascript:window.parent.showGeneralIFramePopup('/usercontrols/RegisterWays.aspx', false, null);" onclick="window.parent._gaq.push(['_trackEvent', 'registerMainForm', 'registration']);">Зарегистрироваться</a>

                    </div>

                </div>

            </div>

        } 

    And a SurfaceController with such action:

    [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 CurrentUmbracoPage();

                    }

                }

                else

                {

                    return CurrentUmbracoPage();

                }

            } 

     

    This controller causes "Can only use UmbracoPageResult in the context of an Http POST when using a SurfaceController form" exception, when I try to return CurrentUmbracoPage()

Please Sign in or register to post replies

Write your reply to:

Draft