Copied to clipboard

Flag this post as spam?

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


  • Thomas Beckert 191 posts 467 karma points
    Nov 14, 2018 @ 11:08
    Thomas Beckert
    0

    Url.GetCropUrl CS1973: 'System.Web.Mvc.UrlHelper' has not such method

    Hi,

    I just wanted to use slimsy in my umbraco instance (Version 7.12.4). But it throws an error, when I want to use @Url.GetCropUrl.

    The error says: Url.GetCropUrl CS1973: 'System.Web.Mvc.UrlHelper' has not such method

    Any idea?

    Thanks to all who read...

  • Dan Diplo 1545 posts 6118 karma points MVP 4x c-trib
    Nov 14, 2018 @ 13:51
    Dan Diplo
    0

    The GetCropUrl() method is an extension method in the Umbraco.Web namespace, so you'll need to include that (if it's not already). So if you are calling it from a view (template) then you'd need to add:

    @using Umbraco.Web
    

    Also, what are the parameters you are passing to the method? If you call it with parameters it doesn't understand then you can get this type of error.

    Generally you need to pass it an image of type IPublishedContent as the first parameter. See https://our.umbraco.com/Documentation/Getting-Started/Design/Rendering-Media/

  • Thomas Beckert 191 posts 467 karma points
    Nov 14, 2018 @ 14:08
    Thomas Beckert
    0

    When I include "@using Umbraco.Web", I still get the same error. When I call it before the @Url like this:

         var featureImage = Umbraco.TypedMedia(Convert.ToInt32(ks.foto));
         <img class="img-circle lazyload" alt="@ks.betrieb" src="@featureImage.Url" 
    
    data-srcset="@Umbraco.Web.Url.GetSrcSetUrls(featureImage, 476, 360)" 
    data-src="@Umbraco.Web.Url.GetCropUrl(featureImage, 476, 360)"
                                                            sizes="auto">          
    

    I got this error:

    Umbraco.Web.UmbracoHelper' does not contain a definition of 'Web'

    I guess, I missed some web.config References during an older update maybe?

  • Dan Diplo 1545 posts 6118 karma points MVP 4x c-trib
    Nov 14, 2018 @ 14:15
    Dan Diplo
    1

    Hi,

    Try calling it like:

    @Url.GetCropUrl(featureImage, 476, 360)
    

    rather than:

    @Umbraco.Web.Url.GetCropUrl(featureImage, 476, 360)
    
  • Thomas Beckert 191 posts 467 karma points
    Nov 14, 2018 @ 14:17
    Thomas Beckert
    0
    @Url.GetCropUrl(featureImage, 476, 360)
    

    This was my initial call. :) That throws the error with the System.Web.Mvc thing...

  • Jakob Bagterp 1 post 71 karma points c-trib
    Feb 07, 2021 @ 21:14
    Jakob Bagterp
    0

    Apart from adding the following namespaces...

    @using System.Web.Mvc
    @using Umbraco.Web
    

    ... did you also create an instance of the UrlHelper? For instance:

    UrlHelper urlHelper = new UrlHelper();
    string imageUrl = urlHelper.GetCropUrl​(mediaItem: imageNode, cropAlias: cropAlias, htmlEncode: false)
    

    More details here:

    https://docs.microsoft.com/en-us/dotnet/api/system.web.mvc.urlhelper?view=aspnet-mvc-5.2

    https://our.umbraco.com/apidocs/v8/csharp/api/Umbraco.Web.UrlHelperRenderExtensions.html

  • Dan Diplo 1545 posts 6118 karma points MVP 4x c-trib
    Nov 14, 2018 @ 14:28
    Dan Diplo
    1

    OK, cool, but you definitely can't use @Umbraco.Web since @Umbraco in this instance would be the UmbracoHelper class rather than the namespace (unfortunately Umbraco calls the property that is exposed in templates @Umbraco, which causes confusion with the namespace of the same name).

    So it sounds like you have a config error. What I'd do is download the zip file from https://our.umbraco.com/download/releases/7124 and then compare your web.config with the one in there. In particular, compare the web.config in your /Views/ folder, as this is where MVC references get added.

  • Thomas Beckert 191 posts 467 karma points
    Nov 14, 2018 @ 14:58
    Thomas Beckert
    0

    I just checked it. Except of the slimsy-entry, the web.config in the /views folder are identical. All reference in the main web.config are also identical. I have no idea anymore...

Please Sign in or register to post replies

Write your reply to:

Draft