Maintain umbracocontext in returned partial view from Ajax call
Hi, I'm hoping someone can help as I'm bit stuck...
I have a page with two partial views, a 'comments list' partial view and an 'add comment form' partial view. On submitting the form I would like the surfacecontroller to return a new comments list partialview to update the existing comments. The comments list partial view renders the comments fine on the first visit to the page but when I add a comment the umbracocontext in the returned comments list partial view appears to be null.
In a nutshell, how can I return a partial view and retain the umbracocontext ie the currentpage.
I don't think this is an Umbraco issue, more the way you're returning the data.
I think what you need to do in your ajax call is add the new comment and then get all comments from that post (you'll have passed the post id into the ajax call to add the comment, so this should be in scope) and when you return that list, replace the markup on the client with the new comment list markup.
Unless you were passing all of the comments along with your ajax call (which would be crazy) there wouldn't be a way to remember these across requests.
thanks for the assistance. I ended up adding a parentId method to the comments model. I could then set this in the surfacecontroller via paremeter and when the page loads for the first time set this via CurrentPage.id. When I render the comments from the Partial view I just use this parentId property from the object each time. It works but doesnt feel like the way it was intended to. Thanks again for your help though
Maintain umbracocontext in returned partial view from Ajax call
Hi, I'm hoping someone can help as I'm bit stuck...
I have a page with two partial views, a 'comments list' partial view and an 'add comment form' partial view. On submitting the form I would like the surfacecontroller to return a new comments list partialview to update the existing comments. The comments list partial view renders the comments fine on the first visit to the page but when I add a comment the umbracocontext in the returned comments list partial view appears to be null.
In a nutshell, how can I return a partial view and retain the umbracocontext ie the currentpage.
Any help would be much appreciated
Regards,
Danny
Hi Danny,
I don't think this is an Umbraco issue, more the way you're returning the data.
I think what you need to do in your ajax call is add the new comment and then get all comments from that post (you'll have passed the post id into the ajax call to add the comment, so this should be in scope) and when you return that list, replace the markup on the client with the new comment list markup.
Unless you were passing all of the comments along with your ajax call (which would be crazy) there wouldn't be a way to remember these across requests.
I hope this helps?
Richard
Hi Richard,
thanks for the assistance. I ended up adding a parentId method to the comments model. I could then set this in the surfacecontroller via paremeter and when the page loads for the first time set this via CurrentPage.id. When I render the comments from the Partial view I just use this parentId property from the object each time. It works but doesnt feel like the way it was intended to. Thanks again for your help though
Regards,
Danny
is working on a reply...