Copied to clipboard

Flag this post as spam?

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


  • Biagio Paruolo 1494 posts 1635 karma points c-trib
    May 02, 2012 @ 12:21
    Biagio Paruolo
    0

    Model type in c#...How declare?

    How declare Model or use Model var in c# ( usercontrol )?

    Thanks

  • gilad 185 posts 425 karma points
    May 02, 2012 @ 12:54
    gilad
    0

    Hi Biagio.

    You can use :

    var currentNode = Node.GetCurrent();

    add this to top : 

    using umbraco.NodeFactory;

  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    May 02, 2012 @ 13:36
    Jeroen Breuer
    0

    You can do it like this:

    dynamic model = new umbraco.MacroEngines.DynamicNode(umbraco.NodeFactory.Node.GetCurrent());

    Here you can find some more info: http://our.umbraco.org/forum/developers/razor/27417-Use-Razor-code-in-UserControl?p=1#comment102639

    Jeroen

  • Biagio Paruolo 1494 posts 1635 karma points c-trib
    May 02, 2012 @ 14:13
    Biagio Paruolo
    0

    Hi, thanks for your help.

    This var items = Model.Parent.Children.Where("customerNo == \"" + profile.Customer_Code + "\""); works in Razor script, but I wish the same code into usercontrol codebehind.

    So I'm going to try this:

             dynamic model = new umbraco.MacroEngines.DynamicNode(umbraco.NodeFactory.Node.GetCurrent());
             var items = model.Parent.Children.Where("customerNo == \"" + profile.Customer_Code + "\"");
  • Jeroen Breuer 4861 posts 12138 karma points MVP 3x admin c-trib
    May 02, 2012 @ 14:14
    Jeroen Breuer
    0

    If it works in Razor that code should also work in the code behind of a UserControl :).

    Jeroen

  • Biagio Paruolo 1494 posts 1635 karma points c-trib
    May 02, 2012 @ 16:51
    Biagio Paruolo
    0

    The problem was to code the @Model variable into codebehind...

  • 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