Copied to clipboard

Flag this post as spam?

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


  • Jason Espin 368 posts 1335 karma points
    Jan 19, 2015 @ 18:28
    Jason Espin
    0

    Using Ajax.ActionLink with a Surface Controller

    Hi all,

    I am currently in the process of building an Ajax-driven payment system within Umbraco and I am currently trying to load a partial view containing an Umbraco form using @Ajax.Action.

    My problem is that with the following settings:

    @Ajax.ActionLink("Book Now", "Availability", "GetAvailability", new AjaxOptions
            {
                HttpMethod = "Post",
                InsertionMode = InsertionMode.Replace,
                UpdateTargetId = "form"
            }, new { @class="btn btn-primary"})
    

    The button generated resolves to the following Url:

    http://localhost:60282/umbraco/RenderMvc/Availability?Length=15
    

    How do I ensure that this correctly resolves to my SurfaceController?

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Jan 20, 2015 @ 10:03
  • Jason Espin 368 posts 1335 karma points
    Jan 20, 2015 @ 10:21
    Jason Espin
    0

    Hi Dave,

    This is for Umbraco v6. The tutorial I found online was also for this older version of Umbraco but I am using the most recent version which it did not seem to work with.

    Cheers,

    Jason

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Jan 20, 2015 @ 10:52
    Dave Woestenborghs
    0

    Hi Jason,

    Using surface controllers in v6 and v7 should work the same. 

    Can you post some code ?

    Dave

  • Jason Espin 368 posts 1335 karma points
    Jan 20, 2015 @ 11:29
    Jason Espin
    0

    I have posted the code above. It is the same as what you sent over in the link except it always fails to direct to

    umbraco/surface/Availability/GetAvailability

    and instead routes to

    umbraco/RenderMvc/AvailabilitySurface?Length=15

    I also have no idea where the Length=15 is coming from as I do not specify that anywhere

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Jan 20, 2015 @ 11:51
    Dave Woestenborghs
    0

    We have this in our view :

    @{
        HtmlHelper.ClientValidationEnabled = true;
        HtmlHelper.UnobtrusiveJavaScriptEnabled = true;
        var ajaxOptions = new AjaxOptions { HttpMethod = "POST", InsertionMode = InsertionMode.Replace, UpdateTargetId = "commentForm" };
    }
    
    <section >
        <div >
            <header>
                <h1>@Model.InnerModel.CommentFormTitle</h1>
            </header>
            @using (Ajax.BeginForm("SubmitMessage", "CommentsSurface", ajaxOptions, new { @id = "commentForm" }))
            {
                <div >
                    <div >
                        <p>
                            @Html.TextBoxFor(m => m.CommentModel.Name, null, new { @placeholder = Model.InnerModel.CommentFormNamePlaceholder })
                            @Html.ValidationMessageFor(m => m.CommentModel.Name)
                        </p>
                        <p>
                            @Html.TextBoxFor(m => m.CommentModel.Email, null, new { @placeholder = Model.InnerModel.CommentFormEmailPlaceholder })
                            @Html.ValidationMessageFor(m => m.CommentModel.Email)
                        </p>
                        <p>
                            @Html.TextAreaFor(m => m.CommentModel.Message, new { @placeholder = Model.InnerModel.CommentFormMessagePlaceholder, @cols = "40", @rows = "10" })
                            @Html.ValidationMessageFor(m => m.CommentModel.Message)
                        </p>
                    </div>
                    <div >
                        <p>
                            <input type="submit" value="@Model.InnerModel.CommentFormButtonLabel">
                        </p>
                    </div>
                </div>
                <input id="commentSubmitBtn" type="hidden" value="@Model.InnerModel.Id" name="modelId"/>
                <input id="lcid" type="hidden" value="@System.Threading.Thread.CurrentThread.CurrentCulture.LCID" name="lcId"/>
            }
        </div>
    </section>

    Maybe this can help.

    Dave

  • Jason Espin 368 posts 1335 karma points
    Jan 20, 2015 @ 16:30
    Jason Espin
    0

    This still does not work for me and fails to direct to the Surface Controller correctly.

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Jan 20, 2015 @ 16:51
    Dave Woestenborghs
    0

    Can you post all your code ? Controller..view ... etc..

    Dave

  • Quan 4 posts 74 karma points
    Apr 02, 2020 @ 14:13
    Quan
    0

    Jason Espin, did you ever manage to solve this? Curiously, five years later, I am exactly in the same spot, but with Umbraco 8. As far as also getting the "Length" attribute after the route.

Please Sign in or register to post replies

Write your reply to:

Draft