Copied to clipboard

Flag this post as spam?

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


  • Tony 105 posts 163 karma points
    Aug 02, 2016 @ 20:38
    Tony
    0

    Access page content on Category Page

    Im on a view (the category one). How do I access umbraco fields from here? Ive tried all teh usual Model.AsDynamic and Umbraco.Field etc.. I just need to access content :'(

  • Lee 1130 posts 3088 karma points
    Aug 03, 2016 @ 07:01
    Lee
    0

    I assume Category is just an Umbraco node? If so, you would get the properties like you would normally?

  • Tony 105 posts 163 karma points
    Aug 03, 2016 @ 08:24
    Tony
    0

    Yeah Ive tried all the normal ways. Ive drilled down in to the model, and everything I can find but cant access teh data. I think its because its using the Merchello model UmbracoViewTemplate<MerchelloModel>() and thats not allowing access.

    The only way I can think is to create my own view model. Have the merchello model within that and get the umbraco context into my viewmodel. But that seems overkill when I just need to access one boolean value from the content

  • Lee 1130 posts 3088 karma points
    Aug 03, 2016 @ 09:37
    Lee
    0

    Ah ok, you are using a starter kit? Is it the old Bazaar?

  • Tony 105 posts 163 karma points
    Aug 03, 2016 @ 12:14
    Tony
    0

    Sorry, should have said Im using fasttrack. :)

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Aug 03, 2016 @ 15:30
    Rusty Swayne
    0

    Tony,

    The category page in FastTrack is an Umbraco page that has a property on it named "products" which is a custom property type.

      var categoryProducts = Model.products;
    

    This returns an object of type

    ProductContentListView : IEnumerable<IProductContent>

    IProductContent is IPublishedContent so you should still be able to access properties directly with Umbraco extensions.

    Can you post a snippet that you are having trouble with?

  • Tony 105 posts 163 karma points
    Aug 03, 2016 @ 16:08
    Tony
    0

    Ill give this a go in a bit when I get back. In visual studio it doesnt pick up products (shows in red) so I was unable to see anythin gin there when debugging

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Aug 03, 2016 @ 16:32
    Rusty Swayne
    0

    That could be the ModelsBuilder (if you're using that) and depending on your setting. I've noticed that in PureLive mode myself.

  • Tony 105 posts 163 karma points
    Aug 06, 2016 @ 07:41
    Tony
    0

    Im trying

    @Model.Products.Content.GetPropertyValue("showListing")
    

    But getting this error

    CS1061: 'Merchello.Web.Models.Ui.Rendering.ProductContentListView' does not contain a definition for 'Content' and no extension method 'Content' accepting a first argument of type 'Merchello.Web.Models.Ui.Rendering.ProductContentListView'
    

    I cant step into the Product object as in VS it gives this error

    error CS0103: The name 'Products' does not exist in the current context
    

    Which is rather frustrating.

    The only way I can see to access it is with the following

    Model.ContentSet.Last().GetPropertyValue("showListing")
    

    Which isnt great as the current page might not be the last content set (Category)

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Aug 06, 2016 @ 15:18
    Rusty Swayne
    0

    Hey Tony - this sounds like an issue with Models Builder and/or how the reference to the generated model. What setting do you have in the web.config for MB?

  • Tony 105 posts 163 karma points
    Aug 06, 2016 @ 17:29
    Tony
    0

    It was from a totally standard umbraco install so its LiveModels and model builder is true. Ive not ever really used this as all my previous builds were before they brought this out and just hijacked the controller

  • Rusty Swayne 1655 posts 4993 karma points c-trib
    Aug 08, 2016 @ 14:46
    Rusty Swayne
    0

    I really like models builder, but you have to make sure you understand how you view is setup in relation to your models builder configuration (web.config).

    By default it installs with "PureLive" which is great for getting things going quickly. However, I've found this setting can be problematic for the VS IDE intellisense albeit the site will generally render fine.

    I usually change it to LiveDll and then finally to Dll as I progress through a project. Changing this means you have to go back and manually press the button to generate the models (in the back office) and then remove the reference in the view(s) to the dynamic models ...

    e.g. Change:

     @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.TextPage>
     @using ContentModels = Umbraco.Web.PublishedContentModels;
    

    to

      @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<TextPage>
    
Please Sign in or register to post replies

Write your reply to:

Draft