Copied to clipboard

Flag this post as spam?

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


  • Steve 472 posts 1216 karma points
    Jun 17, 2014 @ 15:31
    Steve
    0

    Razor Scripts Broken from Upgrade v4 to v6

    I have upgraded from Umbraco 4.11 to 6.1.6 and aparently some of the methods or namespaces have changed and caused a few of my Razor scripts to break. Here is one very basic example, could someone point me in the right direction to fixing the issue? I am sure it is something simple. Thanks!

    @inherits umbraco.MacroEngines.DynamicNodeContext
    
    @{
        var page = @Model.AncestorOrSelf("Category2HomePage");
    
        if ( page.contactPhone != "" ) {
            @page.contactPhone
        } if ( page.contactEmail != "" ) {
            <br />
            <a class="show hide_email" rel="@page.contactEmail">@page.contactEmail</a>
        }
    }
  • Steve Morgan 1349 posts 4459 karma points c-trib
    Jun 17, 2014 @ 15:37
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jun 17, 2014 @ 15:37
    Dennis Aaen
    0

    Hi Steve,

    What about this:

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{
       
    var page = Model.AncestorOrSelf("Category2HomePage");

       
    if(page.contactPhone !=""){
           
    @page.contactPhone
       
    }if(page.contactEmail !=""){
           
    <br />
           
    <a class="show hide_email" rel="@page.contactEmail">@page.contactEmail</a>
       
    }
    }

    Maybe to check if your fields is empty you could use the HasValue.

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{
       
    var page = Model.AncestorOrSelf("Category2HomePage");

       
    if(page.HasValue("contactPhone")){
           
    @page.contactPhone
       
    }if(page.HasValue("contactEmail ")){
           
    <br />
           
    <a class="show hide_email" rel="@page.contactEmail">@page.contactEmail</a>
       
    }
    }

    Hope this helps,

    /Dennis

  • Steve Morgan 1349 posts 4459 karma points c-trib
    Jun 17, 2014 @ 15:38
    Steve Morgan
    0

    Also your errors will be sent to \App_Data\Logs\UmbracoTraceLog.txt that should help you weed them out more quickly! 

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 17, 2014 @ 15:40
    Jeavon Leopold
    0

    @Steve Morgan is bang on, check the link he posted

  • Steve 472 posts 1216 karma points
    Jun 17, 2014 @ 15:50
    Steve
    1

    Thanks everyone, that seemed to fix it. Is there anything else I should be aware of?

  • Steve 472 posts 1216 karma points
    Jun 17, 2014 @ 16:32
    Steve
    0

    I found another error with a Contour script as well here is the error:

    \\umbracoshare\prep\wwwroot_6x\umbraco\plugins\umbracoContour\Views\Form.cshtml(28): error CS0619: 'System.Web.Mvc.HtmlHelper.AntiForgeryToken(string)' is obsolete: 'This method is deprecated. Use the AntiForgeryToken() method instead. To specify custom data to be embedded within the token, use the static AntiForgeryConfig.AdditionalDataProvider property.'

    Should I post this to the Contour forum?

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jun 17, 2014 @ 17:39
    Dennis Aaen
    1

    Hi Steve,

    I was thinking since you have to do some rewite of your Razor, when you are going from Umbraco version 4 to Umbraco 6, then you should consider, to use dynaic razor or stronly typed razor instead of the DynamicNode Razor. Dynamic node Razor is a old legacy Razor and will be deprecated.

    And the rewriting from DynamicNode Razor to Dynamic Razor or Strongly Typed Razor isn´t so hard. There are not so big difference. E.g instead of @Model you´re using the @CurrentPage. You can see the differencehere: http://our.umbraco.org/documentation/reference/templating/macros/Partial-View-Macros/

    But this requires that you also change from using Webforms to using MVC. Here is a cheetsheet on how to convert masterpages to views. http://our.umbraco.org/documentation/cheatsheets/masterpages2views.pdf

    And you have to make some chantes to the webconfig file to run MVC. The only thing you need is to enable this in ~/config/umbracoSettings.config by setting the defaultRenderingEngine setting to MVC as such

    <defaultRenderingEngine>Mvc</defaultRenderingEngine>

    The last thing I would mention is the way you use the the Umbraco library methods, In MVC you call it by using @Umbraco. so if you need to get node by id. In MVC you do it like this: Umbraco.Content(1234);

    By changing from the DynamicNode Razor, to MVC you will get a faster site at the end, and if you upgrade to version 7 later on, then you don´t have to do the conversion again.

    Just my thoughts when you are rewriting your Razor from Umbraco version 4 to version 6 why not go the whole way.

    /Dennis

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 17, 2014 @ 17:43
    Jeavon Leopold
    0

    Great thoughts @Dennis

    One thing I would add is that while it is recommend that you switch to MVC you can continue to use WebForms with the new Razor by converting Razor Macros to Partial View Macros.

  • Steve 472 posts 1216 karma points
    Jun 17, 2014 @ 17:44
    Steve
    0

    Dennis,

    I am a one man show for a medium sized private college, so I am doing as much as I can handle right now. I've thought about Mvc, but quite frankly, don't see much advantage with our site. I know that alot of people are switching to Mvc, but at this time it would require too much time to learn.

  • Steve 472 posts 1216 karma points
    Jun 18, 2014 @ 21:04
    Steve
    0

    The error occurs if you upgrade Umbraco without upgrading Contour to the latest version. There is however an error in the documentation that will cause another issue.  There is an xsltExtensions.config file which allows you to register 3rd party xslt extensions.

    The Contour documentation says to add this line to the file:

        <ext assembly="/bin/Umbraco.Forms.Core" type="Umbraco.Forms.Library" alias="umbraco.contour" >

    But it should be:

        <ext assembly="Umbraco.Forms.Core" type="Umbraco.Forms.Library" alias="umbraco.contour" />

Please Sign in or register to post replies

Write your reply to:

Draft