Copied to clipboard

Flag this post as spam?

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


  • Daniel Gillett 72 posts 149 karma points
    Feb 20, 2017 @ 23:20
    Daniel Gillett
    1

    Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'Map'

    I'm very keen to use the Terratype using the Google Maps Provider.

    I've started a new Umbraco project to test with (currently 7.5.9) and then I installed Terratype and the Terratype.GoogleMapsV3 using NuGet as per your pdf doc.

    I'm trying to do a simple test - 1. I created the datatype (although in Firefox 51 the dropdown lists appear empty but is ok in Chrome)
    2. Then I set up the doctype 3. then the razor template

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @using Terratype
    @{ Layout = "Master.cshtml";
    }
    
    @Html.Terratype(Model.Content.Map,
     @<text>
        <div style="background-color:yellow;">
          This icon is at @Model.Content.Map.Position
        </div>
      </text>
    
    )
    

    But when I follow the example in the pdf I'm getting errors...

    'Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'Map' and no extension method 'Map' accepting a first argument of type 'Umbraco.Core.Models.IPublishedContent' could be found (are you missing a using directive or an assembly reference?)

    Do I need to be creating my own model in .net or should this work out of the box.

    I hope I'm not doing anyting silly!

    Many thanks for your time.

    Daniel

  • Jonathan Richards 288 posts 1742 karma points MVP
    Feb 20, 2017 @ 23:34
    Jonathan Richards
    0

    Hi Daniel,

    The word Map is an example, the actual word you place there is the alias you created in your doctype. If you have created a standard Terratype property like:-

    DocType Alias

    Then Umbraco will have created a field called by whatever you called your alias for you of Type Terratype.Models.Model. You can access that field using @Model.Content.MyAliasThatIUsedToCreateTheTerratypeProperty

    If you have created the Terratype property within a more complex property like Archetype, NestedContent, Grid, Vorto, then you will need to do something more. If you post what your DocType looks like, I might be able to help further.

    Cheers

    Jonathan

  • Daniel Gillett 72 posts 149 karma points
    Feb 21, 2017 @ 20:08
    Daniel Gillett
    1

    Thank you so much for your reply! I just tried changing the alias but it had no difference. What am I doing wrong?

    enter image description here

    ...the same issue. The yellow screen of death error message says "Umbraco.Core.Models.IPublishedContent' does not contain a definition for 'Map' and no extension method 'Map' accepting a first argument of type 'Umbraco.Core.Models.IPublishedContent' could be found (are you missing a using directive or an assembly reference?)"

    I've tried both "Map" and "Map2" aliases.

    ...I keep wondering if I need to create a .Net Model or something as per your Model in the pdf? All I did was install via NuGet (both parts) and then try the example in your pdf.

    It looks like a very good package if I can get it working.

    Many thanks for your help and sorry if I'm being dumb!

    Daniel

  • Jonathan Richards 288 posts 1742 karma points MVP
    Feb 21, 2017 @ 20:35
    Jonathan Richards
    0

    Hi Daniel,

    My mistake, I haven't set up dynamics as cleanly as I would like.

    You have two choices; Keep using Dynamics or switch to Strongly Type. I'll offer both and you can pick whichever you prefer.

    Dynamics

    In you razor template use

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using Terratype;
    
    @((Html as System.Web.Mvc.HtmlHelper).Terratype(CurrentPage.Map as Terratype.Models.Model))
    

    I will try and remove the need for all those casts in the next version of Terratype, which will be out in the next day or so.

    Strongly Type

    In your razor template use

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.Map2>
    @using ContentModels = Umbraco.Web.PublishedContentModels;
    @using Terratype;
    
    @Html.Terratype(Model.Content.Map)
    

    This is strongly typed to your doctype called 'Map2'. The advantage of this is that Visual Studio will give you intellisense for all your properties.

    Cheers

    Jonathan

  • Daniel Gillett 72 posts 149 karma points
    Feb 21, 2017 @ 21:33
    Daniel Gillett
    1

    Brilliant!

    I couldn't get the strongly typed option to work but I did get the Razor version to work. Very easy! thanks very much.

    I would like the stronly typed version to work if possible. When I tried to add the @inherits Umbraco.Web.Mvc.UmbracoTemplatePage line it said there wa a problem (perhaps i'm missing an assembly reference) but when I tried to add the Umbraco.ModelsBuilder.dll reference it said it was already added. lol

    But at leat I got it to work! Thank you! ...I'm building a website for my mother and I'm hoping it will be very easy for her to use. ;-)

    Thanks for your time. Daniel

    BTW here is the error from the strongly typed error:

    enter image description here

  • Jonathan Richards 288 posts 1742 karma points MVP
    Feb 21, 2017 @ 21:44
    Jonathan Richards
    0

    Hi Daniel,

    Great to hear that you have it working in Dynamics. As for the strongly typed version, I can't help but notice you have spelled

    @using ContentModels = Umbraco.Web.PublishedcontentModels;
    

    with a lowercase 'c' for Content, where it should be Uppercase.

    Barring that it wasn't just an error with you copying and pasting to this forum, then yeah, something isn't right. I suspect together we could figure out the issue, but its not particularly relevant to Terratype.

    Cheers, and good luck with your Mother's website.

    Jonathan

  • Daniel Gillett 72 posts 149 karma points
    Feb 21, 2017 @ 22:29
    Daniel Gillett
    1

    Ok, this is interesting. I've checked and pasted your code above re the strongly typed version and I still had problems. I checked this against the Razor version and there are some differences with the aliases... I got it to work buy referencing the datatype name and the doctype alias. (images below) ...but at least I got it to work on both Razor and Strongly Typed version.

    In the razor version, I refer to Map (CurrentPage.Map) But in the strongly typed version I had to use Map2 as the model. Map2 is the Datatype name and Map is the alias name of the doctype. the cshtml file in the image shows both versions that work (Razor is commented out to show you the exmaple of both that are now working)

    Perhaps it's me. It's past midnight here and i'm drinking Raki. Otherwise, there is a difference between the Datatype name and the DocType alias when using Razor Vs Strongly Typed.

    Glad to have it working now! cheers!

    Razor Vs Strongly Typed - differences referencing the model name

    Developer DataType name

    Settings alias name

  • Jonathan Richards 288 posts 1742 karma points MVP
    Feb 22, 2017 @ 00:21
    Jonathan Richards
    0

    hehe, I do think its the Raki, because what you have posted in your screenshot is the same as what I typed originally in my second post. You are correct that your doctype is called 'map2', yet your property type alias (data type) is 'map'.

    I'm really pleased its all working. I know I'm checky to ask, but if you could assign one of my posts as the 'correct answer', this thread can be archived correctly.

    On a separate note, you will be pleased to note, I have written the code to remove the casting you had to do to get Dynamics to work. And I will be releasing this soon.

    Cheers

  • Jonathan Richards 288 posts 1742 karma points MVP
    Feb 24, 2017 @ 10:11
    Jonathan Richards
    1

    Just as a follow up, as of release 1.0.7, you can access Terratype Dynamic values in Razor using any of the following three lines (They all achieve the same result)

    @Html.Terratype("mapAlias")
    @Html.Terratype(Model.Content.GetProperty("mapAlias"))
    @Html.Terratype(Model.Content.GetProperty("mapAlias").Value)
    
  • Daniel Gillett 72 posts 149 karma points
    Feb 26, 2017 @ 11:58
    Daniel Gillett
    0

    Thanks so much for your help! I'm really liking Terratype. This is the map package that I want to use in all of my upcoming projects.

    I prefer to use strongly typed code wherever I can so I created a simple controller, accessed the model and passed it into my razor. ...Hope I'm doing it right...

        public ActionResult RenderMap()
        {
            Terratype.Models.Model map = CurrentPage.GetPropertyValue<Terratype.Models.Model>("googleMap");
            return PartialView(PartialViewPath("_Map"), map);
        }
    

    the above passes the the Terratype model object on to the razor page for rendering...

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<Terratype.Models.Model>
    @using Terratype;
    @if(Model != null)
    {
        @Html.Terratype(Model)
    }
    

    ...of course the complete object is passed so I can also use all of the other properties as well.

    the only little niggle is that I don't seem to be able to save the data type's settings when I set it. things like the map style don't seem to be saving...

    thanks again for a really great and slick tool!

  • Jonathan Richards 288 posts 1742 karma points MVP
    Feb 26, 2017 @ 14:46
    Jonathan Richards
    0
    I don't seem to be able to save the data type's settings when I set it. things like the map style don't seem to be saving...
    

    Just to check, are you saying that you are unable to set the styling when you are creating the Terratype datatype, like on this screen

    Create Terratype Data Type

    or that you can't set the styling yourself using code, because the latter is deliberate, as I don't want people trying to set up the provider incorrectly - all the setters are private.

    You can use the options argument in the @Html.Terratype() command to override styling when the map is being rendered if you want to create your own styling.

  • Daniel Gillett 72 posts 149 karma points
    Mar 04, 2017 @ 09:08
    Daniel Gillett
    0

    Sorry it's taken me this long to get back to you! Things are very busy here an I've been unable to work on my mother's site, where I'm testing/using the Terratype.

    Because this is a different issue, i've created a new bug/question ...hope that's ok.

    Many thanks! Daniel

Please Sign in or register to post replies

Write your reply to:

Draft