Copied to clipboard

Flag this post as spam?

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


  • Barry Fogarty 493 posts 1129 karma points
    Aug 20, 2014 @ 16:37
    Barry Fogarty
    0

    Retain UmbracoContext when AJAX posting to a surface controller

    I would like to post a form using Ajax.BeginForm() to a surface controller while still retaining the Umbraco context.  Is this possible?  If I use Html.BeginUmbracoForm in my partial view, the context is populated in the surfacecontroller and I can use CurrentPage etc, but this is not the case with Ajax.BeginForm.  I want to use Ajax.BeginForm as I have everything all hooked up nicely with unobtrusive jquery validation.

    My understanding is there is a hidden field posted with the form data (ufprt) when using BeginUmbracoForm, which hooks up the context - but there is no equivalent Ajax.BeginUmbracoForm.

    I can work around this by posting a node ID reference to the surface controller but it seems a bit daft to do this - I might as well just use standard MVC or route hijacking. 

    This logged issue seems to suggest you can get the context with Ajax but its not working for me.  Other Our threads I have read suggested others have worked around it by including a node ID with the post.

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    Aug 20, 2014 @ 23:12
    Andy Butland
    0

    I've always passed the nodeId as a parameter Barry, and then Umbraco.TypedContent() to get the content that Id relates too.  As I understood that was just how it was given the idea of "CurrentPage" doesn't make so much sense from an Ajax request.  

    Andy

  • Barry Fogarty 493 posts 1129 karma points
    Aug 21, 2014 @ 15:57
    Barry Fogarty
    0

    Cheers Andy, yep went with this kinda thing in the end, so I did not have to pass in an ID (in this case I actually needed properties from a global settings node)

    Umbraco.TypedContentAtRoot().First().Descendants(DocAlias.ContactForm).FirstOrDefault();

    I still think it would be handy to have the umbraco context for the page containing the form making the AJAX request - if you are handling the post in a surface controller. Seems for now we'll just need to continue passing in an ID.

Please Sign in or register to post replies

Write your reply to:

Draft