Copied to clipboard

Flag this post as spam?

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


  • Newbraco 41 posts 164 karma points
    May 02, 2018 @ 13:43
    Newbraco
    1

    Error : "Cannot bind source type Umbraco.Web.Models.RenderModel to MyModel"

    I have a Page Template with the content below. When I visit the page I get the error

    > Cannot bind source type Umbraco.Web.Models.RenderModel to MyModel

    My Page Template:

    [at]inherits UmbracoViewPage[MyNameSpace.MyModel]
    
    [at]{
        Layout = "HomeMaster.cshtml";
    }
    

    MyModel looks like this

    public class MyModel : RenderModel
    {
        public MyModel(IPublishedContent content, CultureInfo culture) : base(content, culture)
        {
        }         
    }
    

    My Controller:

        public override ActionResult Index(RenderModel model)
        {
            var myModel  = new MyModel(model.Content, model.CurrentCulture);             
            return CurrentTemplate(myModel);
        }
    

    This is a copy-paste from another (working) PageTemplate/Controller/Model-set in my project, but I really cant see the difference.

  • Dave Woestenborghs 3387 posts 11466 karma points MVP 6x admin c-trib
    May 02, 2018 @ 13:53
    Dave Woestenborghs
    0

    Hi,

    What model do you have set on your HomeMaster.cshtml ?

    This is probably different

    Dave

  • Newbraco 41 posts 164 karma points
    May 02, 2018 @ 14:06
    Newbraco
    0

    what do you mean by model? I have

    [at]inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    

    in my HomeMaster.cshtml, so that should be RenderModel

    The other page I have copy-pasted from had the same master page and that page works ok.

    If I set

    [at]inherits UmbracoViewPage[MyNameSpace.MyModel]

    on my working page and visits the working page I get the same error message for that page.

    I have also tried to set Layout = null;

  • Dave Woestenborghs 3387 posts 11466 karma points MVP 6x admin c-trib
    May 02, 2018 @ 14:08
    Dave Woestenborghs
    0

    Where did you store the Model cs file ? Is it in a seperate VS project ? Or is it placed in a App_Code folder ?

    Dave

  • Sumesh KP 32 posts 104 karma points c-trib
    Aug 30, 2020 @ 07:24
    Sumesh KP
    0

    im placing in the app_code. and its not working

  • Dave Woestenborghs 3387 posts 11466 karma points MVP 6x admin c-trib
    May 02, 2018 @ 14:15
    Dave Woestenborghs
    1

    And what is the name of your controller ?

    Dave

  • Newbraco 41 posts 164 karma points
    May 02, 2018 @ 14:15
    Newbraco
    0

    The MyModel.cs?

    In [MyMVCProject]\ViewModels\

    (the class is actually called MyViewModel )

    (same VS-project as Umbraco, ie a plain MVC-project with Umbraco nuget-installation)

  • Newbraco 41 posts 164 karma points
    May 02, 2018 @ 14:16
    Newbraco
    0

    The controller is named

    \Controllers\MyPageController.cs

    and my page template is named \Views\MyPage.cshtml

  • Dave Woestenborghs 3387 posts 11466 karma points MVP 6x admin c-trib
    May 02, 2018 @ 14:20
    Dave Woestenborghs
    101

    Is your document type called "MyPage" ?

    To do routehijacking the part before Controller needs to match your documenttype alias.

    See the docs about that : https://our.umbraco.org/documentation/Reference/Routing/custom-controllers

    Dave

  • Newbraco 41 posts 164 karma points
    May 02, 2018 @ 14:59
    Newbraco
    0

    SUPER!!!

    Thanks! You saved my day :D

    (I had three similar page templates that didnt seem to need an document type (except for permissions to add it in the hierarchy), so I created one for my three page templates, so I was forced to use a dfferent name. This is corrected now and I will be using one DT for each PT)

  • Dave Woestenborghs 3387 posts 11466 karma points MVP 6x admin c-trib
    May 02, 2018 @ 15:00
    Dave Woestenborghs
    1

    Nice to hear that the issue is solved. Don't forget to mark the topic as solved.

    Dave

  • Marc-André 63 posts 278 karma points
    Aug 28, 2019 @ 15:19
    Marc-André
    0

    Saved my day too :)

  • Newbraco 41 posts 164 karma points
    May 03, 2018 @ 06:04
    Newbraco
    0

    Hmm. I though Id already done that. (When ypu wrote that post) Isnt it marked as solved?

Please Sign in or register to post replies

Write your reply to:

Draft