Copied to clipboard

Flag this post as spam?

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


  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Oct 20, 2014 @ 18:24
    Ismail Mayat
    0

    ModelsBuilder in route hijack

    I am using Modelsbuilder and all works fine in my views. What i am trying to do is get the strongly typed object in a route hijack. However only way i can see how is

     public override ActionResult Index(RenderModel model)

            {

                var hardwater = new Hardwater(model.Content);

     

                List<Dictionary<string,string>> accordionContent = new List<Dictionary<string, string>>();

     

               //do stuff then pass to view

     

                return base.Index(model);

     

            }

    Is this only way of doing it?

     

    Regards

    Ismail

     

  • Stephen 767 posts 2273 karma points c-trib
    Oct 20, 2014 @ 18:27
    Stephen
    0

    What would be the exact CLR type of model.Content in that case? Because the strongly typed models factory is implemented at cache level, it should already be strongly typed.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Oct 20, 2014 @ 18:29
    Jeroen Breuer
    1

    Hello,

    Try this:

    var hardWater = CurrentPage as Hardwater;

    Jeroen

  • Stephen 767 posts 2273 karma points c-trib
    Oct 20, 2014 @ 18:31
    Stephen
    100

    @Jeroen - no sure he has a "CurrentPage" as this takes place in a hijacked controller. So only RenderModel.Content, which is an IPublishedContent, but should be strongly typed, so it would rather be...

    var content = model.Content as Hardwater;
    if (content == null) throw new Exception("oops?");
  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Oct 20, 2014 @ 18:35
    Jeroen Breuer
    0

    Both can work :-). 

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Oct 20, 2014 @ 18:42
    Ismail Mayat
    0

    Guys,

    Many thanks i went for stephans suggestion works a treat.

    I have to say I am loving modelsbuilder, we had talk last week at Manchester meetup all about code first etc, we are trying to get strongly type objects and version control, my personal opinion after trying quite a few things is usync and models builder is a very happy pragmatic solution its easy to use and seems to be performant.

    Regards

    Ismail

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    Oct 20, 2014 @ 18:45
    Jeroen Breuer
    0

    If you want to have some more examples on how the Models Builder can be used with route hijacking check out the Hybrid Framework: http://our.umbraco.org/projects/developer-tools/hybrid-framework-for-umbraco-v7

    Jeroen

Please Sign in or register to post replies

Write your reply to:

Draft