Copied to clipboard

Flag this post as spam?

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


  • Danny Leech 36 posts 114 karma points
    Jan 29, 2015 @ 16:09
    Danny Leech
    0

    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

  • Richard Terris 273 posts 715 karma points
    Jan 30, 2015 @ 17:46
    Richard Terris
    0

    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

  • Danny Leech 36 posts 114 karma points
    Jan 31, 2015 @ 20:17
    Danny Leech
    0

    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 

Please Sign in or register to post replies

Write your reply to:

Draft