Copied to clipboard

Flag this post as spam?

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


  • Annfinn Thomsen 24 posts 84 karma points
    Dec 10, 2013 @ 18:07
    Annfinn Thomsen
    0

    Context Must Implement System.Web.WebPages.WebPage

    Hello,

    I'm trying to get a page to show all PDF files in a media folder (ID is 2465).

    I have the following code:

    @inherits Umbraco.Web.Macros.PartialViewMacroPage
    
    
    @{
        var rootNode = Umbraco.TypedMedia(2465);
        foreach (var item in rootNode.Children)
        {
             <p>@item.DocumentTypeAlias - @item.Id - @item.GetPropertyValue("umbracoFile")</p>
        }
    }
    

    But I can't get it to work. I'm getting this error:

    Compiler Error Message: CS1061: 'Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'GetPropertyValue' and no extension method 'GetPropertyValue' accepting a first argument of type 'Umbraco.Core.Models.IPublishedContent' could be found (are you missing a using directive or an assembly reference?)

    If I remote @item.getPropertyValue... I get the "Context Must Implement System.Web.WebPages.WebPage" error. What am I doing wrong?

     

    Thanks in advance.

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 10, 2013 @ 18:13
    Jeavon Leopold
    0

    Hi Annfinn,

    Two quick questions, what version of Umbraco are you using and could you please post the content of your /Views/Web.Config file?

    Thanks,

    Jeavon

  • Annfinn Thomsen 24 posts 84 karma points
    Dec 10, 2013 @ 19:13
    Annfinn Thomsen
    0

    Hello,

    Thanks for getting back to me.

    Web.config:

    <?xml version="1.0"?>
    
    <configuration>
      <system.web.webPages.razor>
        <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
        <pages pageBaseType="System.Web.Mvc.WebViewPage">
          <namespaces>
            <add namespace="System.Web.Mvc" />
            <add namespace="System.Web.Mvc.Ajax" />
            <add namespace="System.Web.Mvc.Html" />
            <add namespace="System.Web.Routing" />
                    <add namespace="Umbraco.Web" />
                    <add namespace="Umbraco.Core" />
                    <add namespace="Umbraco.Core.Models" />
                    <add namespace="Umbraco.Web.Mvc" />
          </namespaces>
        </pages>
      </system.web.webPages.razor>
    
      <appSettings>
        <add key="webpages:Enabled" value="false" />
      </appSettings>
    
      <system.web>
        <httpHandlers>
          <add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>
        </httpHandlers>
    
        <!-- Enabling request validation in view pages would cause validation to occur after the input has already been processed by the controller. By default MVC performs request validation before a controller processes the input. To change this behavior apply the ValidateInputAttribute to a controller or action. -->
        <pages
            validateRequest="false"
            pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
            userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
          <controls>
            <add assembly="System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" namespace="System.Web.Mvc" tagPrefix="mvc" />
          </controls>
        </pages>
      </system.web>
    
      <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
    
        <handlers>
          <remove name="BlockViewHandler"/>
          <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
        </handlers>
      </system.webServer>
    </configuration>
    

     

    Version: Umbraco v6.1.5 (Assembly version: 1.0.4993.19246)

     

     

     

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 11, 2013 @ 10:23
    Jeavon Leopold
    0

    The XML looks broken but it's probably just the posting here. Generally the contents looks ok.

    Is your MacroPartial being saved in the /Views/MacroPartials folder? Also how are you rendering the Macro, through RTE or in a template (Webforms or Mvc?)?

  • Annfinn Thomsen 24 posts 84 karma points
    Dec 11, 2013 @ 17:17
    Annfinn Thomsen
    0

    Hello Jeavon,

    I reposted the web.config, dunno why the formatting went brokered! :)

    I'm getting the errors I listed in my first post in the /umbraco/#developer -->Scripting files --> *.cshtml file. It wont let me save it. Normally I use WebMatrix. WebMatrix let's me save the file, but it returns an error. I could send you the link to the homepage (the URL page that gets the error) in a PM if you want.

    In WebMatrix, the CSHTML files are stored in MacroScripts.

    Any thoughts?

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 11, 2013 @ 17:30
    Jeavon Leopold
    101

    Ah ok, that's the problem.

    MacroScripts folder should only be used to store the legacy Razor Macros. What you are creating here is a Partial View Macro and these must be stored in /Views/MacroPartials otherwise it will not work.

    Are you using WebForms or MVC template?

    Jeavon

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 11, 2013 @ 17:32
    Jeavon Leopold
    0

    p.s. you create them in "Developer -> Partial View Macro Files"

  • Annfinn Thomsen 24 posts 84 karma points
    Dec 11, 2013 @ 17:38
    Annfinn Thomsen
    0

    Funny how that worked like a charm! :)


    Thanks allot!! :D

  • Annfinn Thomsen 24 posts 84 karma points
    Dec 11, 2013 @ 17:43
    Annfinn Thomsen
    0

    To answer your question, I'm using WebForms.

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Dec 11, 2013 @ 17:44
    Jeavon Leopold
    0

    Great, use Partial View Macros for all of your logic, that is the recommend approach for v6/v7 Webforms.

  • Daniel Bardi 927 posts 2562 karma points
    Jan 10, 2014 @ 22:41
    Daniel Bardi
    0

    I can currently render macros in webforms like this:

    <umbraco:Macro FileLocation="~/MacroScripts/BreadCrumb.cshtml"/>

    I don't need to create a Macro in the backoffice.  This method has been great to use with uSiteBuilder.

    I want the same funcationality with Partal View Macro.

    How would render a Partial View Macro in v6 using webforms without creating a macro in the backoffice?

Please Sign in or register to post replies

Write your reply to:

Draft