Copied to clipboard

Flag this post as spam?

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


  • David Peck 690 posts 1896 karma points c-trib
    Apr 28, 2015 @ 17:30
    David Peck
    0

    BeginUmbracoForm setting the action as the current path

    I have a Partial (called via Html.Action on the main View) that displays my form, with the exception of the

    tag. This has the action set to the path of the current page. Any idea why? 
    @using SMG.Web.Infrastructure.Controllers.Surface
    @model LoginFormViewModel
    <div class="login-form">
        @using (Html.BeginUmbracoForm("LoginForm"))
        {
            @Html.AntiForgeryToken()
            <fieldset>
                <legend>Login</legend>
                <div class="editor-label">
                    @Html.LabelFor(m =&gt; m.UserName)
                    @Html.EditorFor(m =&gt; m.UserName)
                    @Html.ValidationMessageFor(model =&gt; model.UserName)
                </div>
                <div class="editor-label">
                    @Html.LabelFor(m =&gt; m.Password)
                    @Html.EditorFor(m =&gt; m.Password)
                    @Html.ValidationMessageFor(model =&gt; model.Password)
                </div>
            </fieldset>
            <p>
                <input type="submit" value="Login" />
            </p>
        }
    </div>

    Controller:

    namespace SMG.Web.Infrastructure.Controllers.Surface
    {
        public class LoginSurfaceController : SurfaceController
        {
            [HttpGet]
            [ChildActionOnly]
            [ActionName("LoginForm")]
            public ActionResult LoginFormGet()
            {
                return PartialView("LoginForm", new LoginFormViewModel());
            }
    
            [HttpPost]
            [ActionName("LoginForm")]
            public ActionResult LoginFormPost(LoginFormViewModel model)
            {
                if (ModelState.IsValid)
                {
                    if (Membership.ValidateUser(model.UserName, model.Password))
                    {
                        FormsAuthentication.SetAuthCookie(model.UserName, true);
                        return RedirectToCurrentUmbracoPage();
    
                    }
                    TempData["Status"] = "Invalid username or password";
                    return RedirectToCurrentUmbracoPage();
                }
                return RedirectToCurrentUmbracoPage();
            }
        }
    }
    

    The only complexity that I can think of with this application is that I've played around with the UrlProviderResolver and ContentFinderResolver, but I wouldn't think either are involved in Url Routing in this way.

  • David Peck 690 posts 1896 karma points c-trib
    Apr 28, 2015 @ 17:53
    David Peck
    0

    I've removed all my Resolver stuff, and it made no difference. It's just like the 'auto routing' has broken, but I can't any information on this to help fix it.

    Also if I hard code the form tag (action="/umbraco/surface/LoginSurface/LoginForm") it does go through to my Controller Action ok, but then it complains about "Cannot find the Umbraco route definition in the route values, the request must be made in the context of an Umbraco request" at

    return RedirectToCurrentUmbracoPage();
  • David Peck 690 posts 1896 karma points c-trib
    Apr 28, 2015 @ 22:24
    David Peck
    1

    Ok, so there isn't really a problem here! It's mostly my fail, however in case anyone else is as stupid as me: BeginUmbracoForm correctly sets the action attribute as the current path. Routing happens via some magin. I understood this page to suggest otherwise, and I think perhaps this is an update. The reason I thought it wasn't working was because I hadn't realised my action was being called but exiting silently.

Please Sign in or register to post replies

Write your reply to:

Draft