Copied to clipboard

Flag this post as spam?

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


  • Edvin 9 posts 99 karma points
    Oct 09, 2018 @ 11:18
    Edvin
    0

    Custom "model" does not exist in the current context

    Hi,

    sry for this stupid question, but I am fairly new to Umbraco . I am currently editing a uskinned template , and I am wondering what I am doing wrong. I want to create a custom data type, let's call it "mycustomtype".

    I create one in the Data Type section without template, name the alias "mycustomtype". I set it under Advanced Page Components. The master template calls a View, which then calls a partial view called component switch. In that view I see there is a switch case with all data types from the template (components). I add another switch case with my custom one:

     case mycustomtype.ModelTypeAlias:
                @Html.Partial("USNAdvancedPageComponents/mycustomtype", (mycustomtype)Model)
                break;
    

    And i get the error on the case line that it doesn't recognize it:

    Compiler Error Message: CS0103: The name 'mycustomtype' does not exist in the current context
    

    Do I miss here something obviously or? Do I need to rebuild the models? I thought it get's done automatically when I create a data type? Or is this uskinned template related?

    Sry , I am still wrapping my head around umbraco in this short time.

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Oct 09, 2018 @ 11:42
    Dan Diplo
    0

    There are different modes for the Model Builder - some will automatically build models on change, some require manual rebuilding.

    There's documentation for the modes here: https://our.umbraco.com/documentation/reference/templating/modelsbuilder/Builder-Modes

    PS. What you are calling a "data type" is actually a "document type" in Umbraco terminology. A "data type" is an instance of a property editor (eg. a textbox). I know, it's confusing, but just so you know in future :)

  • Edvin 9 posts 99 karma points
    Oct 09, 2018 @ 12:25
    Edvin
    0

    Thx, you are right about document type.

    Btw It's PureLive, also when I search the generated model I see the class generated.

    I am really not sure what's happening, It's generated, it's spelled right.

    Seems like the error is misleading?

  • Edvin 9 posts 99 karma points
    Oct 09, 2018 @ 13:39
    Edvin
    100

    Okey, I found the problem.

    It was the naming of the model alias. Not sure why or how but the issue is following:

    If I created a custom document type and named it's alias customtype, the model would be generated but it would rename it somehow to Customtype.

    So when I typed customtype, it didn't exist.

    Not sure if this is umbracos fault or the theme itself, but glad I figured it out.

Please Sign in or register to post replies

Write your reply to:

Draft