Copied to clipboard

Flag this post as spam?

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


  • Vilius Janulis 38 posts 79 karma points
    Mar 12, 2014 @ 10:57
    Vilius Janulis
    0

    MVC get node/model properties in main controller

    Hi,

    So basically I have custom attribute where I need to pass two parameters. I know how to do it in surface controller but how to you get node properties in main controller ?

    public class LoginController : RenderMvcController
    {
        [IsLoggedInRedirect("/leverandoerer.aspx", "/boligorganisationer.aspx")]
        public override ActionResult Index(RenderModel model)
        {
            return CurrentTemplate(model);
        }
    }
    

    and the url parameters passed have to be taken from the Login document type. So how do i get model or currentpage there ? if not possible how it should be done other wise ?

  • Yasir Butt 162 posts 372 karma points
    Mar 12, 2014 @ 13:11
    Yasir Butt
    0

    you should be able to access via CurrentPage.GetPropertyValue("yourproperty")

    Other way is model.Content.GetPropertyValue("yourproperty")

  • Vilius Janulis 38 posts 79 karma points
    Mar 12, 2014 @ 13:19
    Vilius Janulis
    0

    I can get CurrentPage in Surface controller but not in the main controller.

    In main non of the above works. Any more ideas ?

  • Yasir Butt 162 posts 372 karma points
    Mar 12, 2014 @ 13:31
    Yasir Butt
    0

    I cant see that why can you not access them but i tried like it and it works, what problem are you getting actually?

    public class LoginController : RenderMvcController  

    {

           //

            // GET: /Login/

            public override ActionResult Index(RenderModel model)

            {

                CurrentPage.GetPropertyValue("property");

                model.Content.GetPropertyValue("property");

                return CurrentTemplate(model);

            }

     

        }

     

  • Yasir Butt 162 posts 372 karma points
    Mar 12, 2014 @ 13:33
    Yasir Butt
    0

    i am using another way where i am using my custom model

     public class MasterController : RenderMvcController

        {

            //

            // GET: /Master/

            

            protected ViewResult View(MasterModel model)

            {

     

                CurrentPage.GetPropertyValue("pageTitle");

                return base.View(null, model);

            }

    }

  • Vilius Janulis 38 posts 79 karma points
    Mar 12, 2014 @ 13:36
    Vilius Janulis
    0

    Both ways you are getting it inside Action. I need it outside.

        [IsLoggedInRedirect(Currnet page does not work here, Currnet page does not work here)]
        public override ActionResult Index(RenderModel model)
        {
            return CurrentTemplate(model);
        }
    
  • Yasir Butt 162 posts 372 karma points
    Mar 12, 2014 @ 13:56
    Yasir Butt
    0

    Hmm! thats the problem. No idea :)

    Why do you want to use it in attribute? what actully do you want to achieve?

  • Vilius Janulis 38 posts 79 karma points
    Mar 12, 2014 @ 14:00
    Vilius Janulis
    0

    I created custom attribute, that uses custom logic to authenticate the users and redirect him to specified landing page based on his parameters. I am using it quite a lot, so would not want to create many repeatable ifs inside it. That is why attribute was a good choice, but now figured out that is hard to fetch umbraco data there.

  • Yasir Butt 162 posts 372 karma points
    Mar 12, 2014 @ 14:18
    Yasir Butt
    0

    Alright! but you can get the Umbraco value in your custom attribute then you have to change your custom attribute either you have to make one which will work for umbraco :)

     

     

  • Vilius Janulis 38 posts 79 karma points
    Mar 12, 2014 @ 15:14
    Vilius Janulis
    0

    So that was the question :) how do you make it work. You also cant access umbraco nodes inside custom attribute.

  • Yasir Butt 162 posts 372 karma points
    Mar 12, 2014 @ 15:23
    Yasir Butt
    100

     

    you can use like this.

    umbraco.uQuery.GetCurrentNode();

     umbraco.uQuery.GetNode(123);

    Umbraco.Core.ApplicationContext.Current.Services.ContentService.GetById(1);

  • Vilius Janulis 38 posts 79 karma points
    Mar 12, 2014 @ 15:33
    Vilius Janulis
    0

    And that one worked ;)

    Thanks a lot

  • Yasir Butt 162 posts 372 karma points
    Mar 12, 2014 @ 15:42
    Yasir Butt
    0

    Great! :)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies