Copied to clipboard

Flag this post as spam?

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


  • Fahad Ayub 71 posts 238 karma points
    Mar 06, 2017 @ 10:53
    Fahad Ayub
    0

    The name 'CurrentPage' does not exist in the current context

    Hi, I have a custom model inherited from RenderModel:

     public class Prd : RenderModel
        {
            public Prd(IPublishedContent content) : base(content) { }
            public IPagedList<ProductViewModel> catalogueProd  { get; set; }
        }
    

    and my view is inherits

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ScentSpider.Models.Prd>
    

    Now in my view when I try to use

    @CurrentPage.GetGridHtml("ProductListLayout") 
    

    I get an error :

    The name 'CurrentPage' does not exist in the current context
    

    Any idea what I an doing wrong here. Thanks

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Mar 06, 2017 @ 11:05
    Alex Skrypnyk
    0

    Hi Fahad

    You can use CurrentPage if inherits like that:

    @inherits UmbracoTemplatePage<ScentSpider.Models.Prd>
    

    You can find some more details here: https://our.umbraco.org/documentation/Reference/Templating/Mvc/querying

    CurrentPage is a dynamic object so the syntax will be shorter but some complex queries might not be doable with that type of object

    Model.Content is strongly typed so when you are in visual studio you can take advantage of the intellisense

    UmbracoViewPage hasn't dynamic objects and now it's a recommended way to do Umbraco development - avoid dynamics, it will be removed in version 8.

    Thanks,

    Alex

  • Fahad Ayub 71 posts 238 karma points
    Mar 06, 2017 @ 11:10
    Fahad Ayub
    0

    Hi Alex, Thanks for your response , I tried to inherits from

    @inherits UmbracoTemplatePage<ScentSpider.Models.Prd>
    

    But I got error :

    The type 'ScentSpider.Models.Prd' cannot be used as type parameter 'TContent' in the generic type or method 'UmbracoTemplatePage<TContent>'. There is no implicit reference conversion from 'ScentSpider.Models.Prd' to 'Umbraco.Core.Models.IPublishedContent'.    ScentSpider 
    
  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Mar 06, 2017 @ 11:14
    Alex Skrypnyk
    0

    What is the "ScentSpider.Models.Prd" type?

  • Fahad Ayub 71 posts 238 karma points
    Mar 06, 2017 @ 11:39
    Fahad Ayub
    0
    public class Prd : RenderModel
        {
            public Prd(IPublishedContent content) : base(content) { }
            public IPagedList<ProductViewModel> catalogueProd  { get; set; }
        }
    
  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Mar 06, 2017 @ 11:14
    Alex Skrypnyk
    0

    How did you return "ScentSpider.Models.Prd" model from controller?

  • Fahad Ayub 71 posts 238 karma points
    Mar 06, 2017 @ 11:40
    Fahad Ayub
    0
    ScentSpider.Models.Prd prodList = new Models.Prd(model.Content);
                prodList .catalogueProd     = ProductHelper.Instance.GetAllCatalogueProducts();
               return CurrentTemplate(prodList );
    
  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Mar 06, 2017 @ 11:45
    Alex Skrypnyk
    0

    Is it code from controller?

    Can you show all controller?

  • Fahad Ayub 71 posts 238 karma points
    Mar 06, 2017 @ 11:57
    Fahad Ayub
    0

    Controller code:

     public class CatalogueController : Umbraco.Web.Mvc.RenderMvcController
        {
            // GET: Catalogue
            public override ActionResult Index(RenderModel model)
            {
                ScentSpider.Models.Prd prodList= new Models.Prd(model.Content);
                prodList.catalogueProd     = ProductHelper.Instance.GetAllCatalogueProducts();
               return CurrentTemplate(prodList);
            }
    }
    

    And my View is:

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ScentSpider.Models.Prd>
    
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @{
        Layout = "Master.cshtml";
    }
    @CurrentPage.GetGridHtml("ProductListLayout")
    

    Thanks

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Mar 06, 2017 @ 13:01
    Alex Skrypnyk
    0

    Fahad, don't use CurrentPage with UmbracoViewPage.

  • Fahad Ayub 71 posts 238 karma points
    Mar 06, 2017 @ 13:32
    Fahad Ayub
    0

    Hi Alex, Could you please suggest how to insert grid ,I created using Umbraco in my page then.

    Thanks

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Mar 06, 2017 @ 13:46
    Alex Skrypnyk
    0

    Fahad, try to use like that:

    @Html.GetGridHtml(Model, "ProductListLayout")
    
  • Fahad Ayub 71 posts 238 karma points
    Mar 06, 2017 @ 14:31
    Fahad Ayub
    0

    Hi Alex, sorry to be a pain. As I am using custom model when I try to use

    @Html.GetGridHtml(Model, "ProductListLayout")
    

    I get an error :

    Argument 2: cannot convert from 'ScentSpider.Models.Prd' to 'Umbraco.Core.Models.IPublishedProperty'    
    

    Thanks

  • Alex Skrypnyk 6150 posts 24110 karma points MVP 8x admin c-trib
    Mar 06, 2017 @ 14:35
    Alex Skrypnyk
    100

    Fahad, try to change your view like that:

    @inherits UmbracoViewPage
    
    @{
        Layout = "Master.cshtml";
    }
    @Html.GetGridHtml(Model, "ProductListLayout")
    

    Because I don't see where do you use "ScentSpider.Models.Prd" model.

    Hope it will help.

    /Alex

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Mar 06, 2017 @ 12:29
    Dan Diplo
    1

    Fahad,

    Could you try:

    @Html.GetGridHtml("ProductListLayout")

    or

    @Model.Content.GetGridHtml("ProductListLayout")

Please Sign in or register to post replies

Write your reply to:

Draft