Copied to clipboard

Flag this post as spam?

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


  • Martin Griffiths 826 posts 1269 karma points c-trib
    Jan 29, 2013 @ 17:27
    Martin Griffiths
    0

    Extension methods on strongly typed Razor in VS2012

    Hi Shannon

    How on earth do I get the extension methods for strongly typed razor like in the example below???

     

    Ancestors()
    Ancestors(int level)
    Ancestors(string nodeTypeAlias)
    AncestorsOrSelf()
    AncestorsOrSelf(int level)
    AncestorsOrSelf(string nodeTypeAlias)
    Descendants()
    Descendants(int level)
    Descendants(string nodeTypeAlias)
    DescendantsOrSelf()
    DescendantsOrSelf(int level)
    DescendantsOrSelf(string nodeTypeAlias)

    I just keep getting the error...no definition or extension method are you missing an assembly reference?

    Martin

     

  • gary 385 posts 916 karma points
    Jan 29, 2013 @ 19:46
    gary
    1

    Hi Martin, 

    If you are using MVC in 4.10 or above - 

    "The Umbraco Helper is just that, a helper that you can call on to retrieve things from Umbraco, to perform tasks like Searching the content index, rendering Macros, stripping HTML from text, finding out if a content item is protected etc. Generally useful and commonly used tasks that would otherwise take you a long time to build yourself. 

    To access the helper in your Views is easy.  Just use @Umbraco.  If you are working in Visual Studio and you you will get Intellisense and it will allow you explore all of its options. "

    The above quote came from here ; http://umbraco.com/follow-us/blog-archive/2012/10/30/getting-started-with-mvc-in-umbraco-410.aspx

    or, there is more here;  http://our.umbraco.org/documentation/Reference/Mvc/

    If you are using the webforms version, it does explain you will not get intellisense with the dynamic. (Sorry, only use the MVC version).

    Hope this hellps you move in the right direction.

    Regards

    Gary

     

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 29, 2013 @ 20:15
    Tom Fulton
    1

    Hi Martin,

    Try adding this using statement to your .cshtml file:

    @using Umbraco.Web

    Ex:

    @using Umbraco.Web
    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
     var url = Model.Content.AncestorsOrSelf("Home").First().NiceUrl()
    }

    Hope this helps,
    Tom 

  • Martin Griffiths 826 posts 1269 karma points c-trib
    Jan 30, 2013 @ 09:07
    Martin Griffiths
    0

    Hi Tom

    That did it!

    The umbraco.dll is changing so rapidly, its damn hard to keep up!

    Shannon, when examples are published on our.umbraco or your own blogsite can you always make sure you include the namespace references?

    Now to re-write all of my XSLT and user controls as MVC/Razor! Hurrah!

    Thanks all

    Martin

     

  • Martin Griffiths 826 posts 1269 karma points c-trib
    Jan 30, 2013 @ 09:28
    Martin Griffiths
    0

    Hi all

    I still have an issue with one of the examples....

    var items = @Model.Content.Children.Where(x => x.IsVisible() && x.Level <= 4)

    IsVisible 'Does not take one arguments'

    What is IsVisible anyway??? Is it published/unplublished of some other property (of which i've not seen in the umbraco back office)

    Thanks

    Martin

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Jan 30, 2013 @ 13:40
    Shannon Deminick
    1

    @Martin,

    Its strange because the @usingUmbraco.Web Should be automatic since it is included in the namespaces references in the web.config for razor views at ~/Views/web.config

    But yeah, i'll include them in examples when i write them.

    IsVisible() is a shortcut to having a property on your documents called 'umbracoNaviHide' which is a true/false property. This is common practice in umbraco that dates way back to when guys wore neon clothes and really tight pants (oh wait, that happens now too :P ). It's just a flag to determine if a document should show up on the front-end or not even if it is published, for example in a menu or other list when iterating over children.

    I think you'll need to include the namespace:

    @usingUmbraco.Core

    as well, but again its strange because these should be automatically resolved based on the web.config.

  • Martin Griffiths 826 posts 1269 karma points c-trib
    Jan 30, 2013 @ 13:53
    Martin Griffiths
    0

    Hi Shannon

    Sorry I was being a bit slow! I use umbracoNaviHide all the time, I just didnt associate it with IsVisible! Doh!

    One last thing, is it possible to use any of the strongly typed goodness in MacroScripts or am I limited to dynamic here??

    Martin

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Jan 30, 2013 @ 14:07
    Shannon Deminick
    0

    MacroScripts will be deprecated in 6+ though we will support them for a while. The replacement is Partial View Macros which use the exact same syntax and object as MVC views. So in 6+, you will be able to use strongly typed goodness with Partial View Macros.

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Jan 30, 2013 @ 17:02
    Tom Fulton
    0

    Shannon - thanks for the info, that explains why I knew about that namespace :)  I had Views/web.config exclude in my VS solution.  After including it, everything works automatically.

    Martin - perhaps this is your problem too?  I can confirm you shouldn't need to add that first namespace.

    -Tom

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Jan 30, 2013 @ 20:39
    Shannon Deminick
    0

    the ~/Views/web.config should get created automatically if it is not there by our view engine. It is required for MVC to work properly. If it is not there, you'll probably end up with problems :)

Please Sign in or register to post replies

Write your reply to:

Draft