Copied to clipboard

Flag this post as spam?

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


  • Tim C 161 posts 528 karma points
    Jun 22, 2016 @ 11:46
    Tim C
    0

    Error using Umbraco.TypedMedia in @functions

    In a partial view, I am listing documents within a foreach loop.

    However, I am parsing the values and making some alterations via some classes in a @functions{ section.

    Within the @functions{ section I can't seem to be able to use

    Umbraco.TypedMedia 
    

    in a class eg

    public class rowOutput{
    
    ...
    
    
    
     private string fetchPropertyValue(
    ...
    
    int mediaId = Int32.Parse(pValue);
        var media = Umbraco.TypedMedia(mediaId);
      pValue = media.Url;           
    

    returns error

    CS0038: Cannot access a non-static member of outer type 'Umbraco.Web.Mvc.UmbracoViewPage<Umbraco.Web.Models.RenderModel>' via nested type 'ASP._Page_Views_Partials_Listings_GenericSearch_cshtml.rowOutput'
    

    I'm hazy as to that this error means. Is there any way round this?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 22, 2016 @ 11:56
    Alex Skrypnyk
    0

    Hi Tim,

    What about '@inherit' attribute of your view? Can you show? Do you use some custom serverside controller?

    Thanks

  • Tim C 161 posts 528 karma points
    Jun 22, 2016 @ 11:57
    Tim C
    0
    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    

    It's not a custom controlled just a standard partial view.

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 22, 2016 @ 11:59
    Alex Skrypnyk
    0

    This problem with inheriting in master and your view, or maybe some custom logic in controllers. Do you have the same inherits attribute in your views?

  • Tim C 161 posts 528 karma points
    Jun 22, 2016 @ 12:01
    Tim C
    0

    Do you mean the template : I am not working in Visual Studio, these are just templates and partial views in the Umbraco backoffice.

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 22, 2016 @ 12:04
    Alex Skrypnyk
    0

    Yes, can you show all your view ?

  • Tim C 161 posts 528 karma points
    Jun 22, 2016 @ 12:06
    Tim C
    0
    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "Master.cshtml";
    }
    
    @section closeBody{
    
        </body>
    }
    
    
    
    
    
    
    
    
                        <!-- main article list -->
                    @Html.Partial("Content/HomePageNews",
    
                                  new ViewDataDictionary {{"userNewsCategories",sUserNewsCategories},{"newsCount",5},{"showPagination","false"},{"showViewAll","1"}}
                                 )
    
  • Tim C 161 posts 528 karma points
    Jun 22, 2016 @ 12:07
    Tim C
    0

    Inherited from master...

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using ContentModels = Umbraco.Web.PublishedContentModels
    @using Umbraco.Core.Security
    @using Umbraco.Core.Models.Membership
    
    
    
    @{
        Layout = null;}
    ...
    
  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 22, 2016 @ 12:11
    Alex Skrypnyk
    0

    Not clear what the problem. It's typical error when rendering with wrong inherits attribute.

  • Tim C 161 posts 528 karma points
    Jun 22, 2016 @ 12:12
    Tim C
    0

    What if I tried putting some c# in app_code to do the conversion from media id to media url : what namespaces would I need?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 22, 2016 @ 12:18
    Alex Skrypnyk
    0

    You need Umbraco context helper.

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jun 22, 2016 @ 12:35
    Alex Skrypnyk
    0

    Are you using static class?

  • Tim C 161 posts 528 karma points
    Jun 22, 2016 @ 13:48
    Tim C
    0

    Managed to find a work around by adding code to App_Code

    public static string getMediaUrl(int mediaId){
                umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current);      
                return umbracoHelper.TypedMedia(mediaId).Url.ToString();
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft