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.
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.
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)
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.
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.
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
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.
is working on a reply...