Copied to clipboard

Flag this post as spam?

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


  • Matthew Wise 271 posts 1373 karma points MVP 5x c-trib
    Aug 30, 2018 @ 14:11
    Matthew Wise
    0

    Models Builder custom property not defined in view file

    Hi,

    I have a models builder class that I have extended to include a filter class which compiles and is accessible within my controller.

    However when I go to the page I get :

    CS1061: 'RenderModel<ArticleListing>' does not contain a definition for 'Filters' and no extension method 'Filters' 
    accepting a first argument of type 'RenderModel<ArticleListing>' could be found (are you missing a using directive or an assembly reference?)
    

    Visual studio also tells me this only in the view

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<Umbraco.Web.PublishedContentModels.ArticleListing>
    
    
    @using (Html.BeginUmbracoForm<ArticleListingController>("FilterArticles", null, new { @class = "listing-form", data_api = Url.SurfaceAction<ArticleListingController>("PagedArticles") }, FormMethod.Post))
    {
        @Html.DropDownListFor(m => m.Filters.FilterDate, Model.Filters.FilterDates)
        @Html.HiddenFor(m => m.Filters.ItemsPerPage)
        @Html.HiddenFor(m => m.Filters.OrderAscending)
    }
    
    @Html.Partial("PagedArticles", Model.Results)
    

    Partial class definition:

    namespace Umbraco.Web.PublishedContentModels
    {
        public partial class ArticleListing 
        {
            public ArticleListingFilters Filters { get; set; }
    
            public Page<IPublishedContent> Results { get; set; }
        }
    }
    

    Thanks

    Matt

  • Frederik Raabye 72 posts 276 karma points MVP 2x c-trib
    Aug 30, 2018 @ 14:27
    Frederik Raabye
    100

    Not too sure but UmbracoViewPage instead of UmbracoTemplatePage when you don't need dynamics?

  • Matthew Wise 271 posts 1373 karma points MVP 5x c-trib
    Aug 30, 2018 @ 14:29
    Matthew Wise
    0

    Thanks :) Works perfectly missus my other failings

    Matt

  • Nik 1612 posts 7258 karma points MVP 7x c-trib
    Aug 30, 2018 @ 14:39
    Nik
    2

    Also, if you did use UmbracoTemplatePage then this....

    Model.Filters.FilterDates
    

    needs to be

    Model.Content.Filters.FilterDates
    

    Just for future reference :-)

    On UmbracoTemplatePage the actual model you define is located on Model.Content as Model is the RenderModel.

Please Sign in or register to post replies

Write your reply to:

Draft