Copied to clipboard

Flag this post as spam?

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


  • Costin 4 posts 74 karma points
    Mar 20, 2018 @ 13:26
    Costin
    0

    How to refresh backoffice view after setting value during ContentService_Saving event handler?

    In a custom made ApplicationEventHandler class I have a ContentService_Saving event handler that changes some values during the page saving process based some admin rules.

    The code looks like this:

    private void ContentService_Saving(IContentService sender, SaveEventArgs<Umbraco.Core.Models.IContent> e)
    {
        foreach (var entity in e.SavedEntities) 
        {
            ...
            entity.SetValue("editCaseVisibility", true);
            entity.SetValue("testTextbox", "tralalala");
            ...
            dynamic json = Newtonsoft.Json.JsonConvert.DeserializeObject(nestedFields);
            ... 
            // changing some of the json's property values
            ...
            // serializing the updated json object
            string serialized = Newtonsoft.Json.JsonConvert.SerializeObject(json);
    
            // updating the Nested Content property in the page
            entity.SetValue("nestedFields", serialized);
        }
    }
    

    The properties "editCaseVisibility" (checkbox) and "testTextbox" (textbox) both get refreshed in the view and show the values I've set in the event handler. However, the Nested Content field "nestedFields" does not show the newly set values. I actually have to manually refresh the whole webpage in the browser to see the new values. Why is that? And is there a solution for it?

  • Marcio Goularte 388 posts 1360 karma points
    Aug 07, 2019 @ 04:34
Please Sign in or register to post replies

Write your reply to:

Draft