Copied to clipboard

Flag this post as spam?

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


  • Manasa 80 posts 201 karma points
    Nov 26, 2014 @ 12:52
    Manasa
    0

    To fetch properties from umbraco backoffice to controller

    Hi all,

     

    How can I fetch selected properties from backoffice into surface controller?

     

    Thanks,

    Manasa

  • Dan Lister 416 posts 1974 karma points c-trib
    Nov 26, 2014 @ 13:05
    Dan Lister
    100

    Hi Manasa,

    What do you mean by selected properties?

    Surface Controllers has no knowledge of what back office page you are on or editing (I think). If you wanted to retrieve properties for a back office page being edited, you would have to pass the current page ID via your Surface Controller request.

    public class MySurfaceController : SurfaceController
    {
        public object MyMethod(int id)
        {
            var page = Umbraco.TypedContent(id);
            var propertyValue = page.GetPropertyValue("alias");
        }
    }
    

    Also, if you are using a controller for a custom back office property editor, you might want to look at using UmbracoAuthorizedApiController instead of SurfaceController.

    I hope that helps.

    Thanks, Dan.

  • Manasa 80 posts 201 karma points
    Nov 26, 2014 @ 13:30
    Manasa
    0

    I tried with your code.

    I get the below error:

    "Umbraco.Core.Models.IPublishedContent" does not contain a definition for GetPropertyValue and no extension method 'GetPropertyValue' accepting the argument of type Umbraco.Core.Models.IPublishedContent could be found.

     

    Thanks,

    Manasa

  • Dan Lister 416 posts 1974 karma points c-trib
    Nov 26, 2014 @ 13:37
    Dan Lister
    0

    Hmmm strange. Do you have a sample of the code you are trying to get working please? It might help find the issue.

    I'm not sure why GetPropertyValue isn't working. You could always try:

    var page = Umbraco.TypedContent(id);
    var propertyValue = page.GetPropertyValue<string>("alias");
    

    Thanks, Dan.

  • Manasa 80 posts 201 karma points
    Nov 26, 2014 @ 13:38
    Manasa
    1

    Thanks Dan.

    We used page.GetProperty("alias name").Value.ToString().

    Fixed the issue.

Please Sign in or register to post replies

Write your reply to:

Draft