Copied to clipboard

Flag this post as spam?

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


  • Advance Ngwarati 25 posts 127 karma points
    Jun 28, 2019 @ 09:17
    Advance Ngwarati
    0

    Help on Nested Content Terratype

    Hello,

    I'm new to Umbraco, using version 7.10.4. I created data types and doc types as per Terratype manual. But when it comes to rendering the map on the fronted i'm getting these errors: .cannot convert from 'Terratype.Options' to 'Terratype.Models.Model' .cannot convert from 'Terratype.Models.Model' to 'System.Func

    foreach (var location in brand.BrandLocation.Where(item => item != null))
    {
    @Html.Terratype(new Options {MapSetId = 1 }, location.Coordinates)
        <span>@location.LocationName</span>
    }
    

    My Terratype Model

    namespace Terratype.Models{
    public class Model {
    
        public Provider Provider { get; internal set; }
        //public Position Position { get; set; }
        public Icon Icon { get; internal set; }
        public int Zoom { get; set; }
        public string Lookup { get; set; }
        public int Height { get; set; }
    }
    
    public class Icon
    {
    }
    
    public class Provider
    {
    }}
    

    I don't know where exactly i'm missing the point.

  • Jonathan Richards 288 posts 1742 karma points MVP
    Jun 28, 2019 @ 10:20
    Jonathan Richards
    0

    Hi Advance Ngwarati

    I don't understand why you are creating your own Terratype Model. The whole point is to the use the one that comes with Terratype. I mean stating the obvious, your one won't render because you haven't written any code for it to do so, you have literally created an empty class with no functionality, but with a similar name to the real one in Terratype package, and then asked why doesn't it work.

    If you want to use the model that is provided in Terratype, you have to create a datatype, place that datatype within your own document type and then create content based on your document type. Only then can you take that content property value and use it to render on the front-end with the command @Html.Terratype(). All of these steps are described in the manual.

    Cheers

    Jonathan Richards

  • Advance Ngwarati 25 posts 127 karma points
    Jun 28, 2019 @ 10:32
    Advance Ngwarati
    0

    Thank you Jonathan,

    I was so confused with that model in the manual, now the issue is i'm using modelsbuilder api so when i generate the models, it throws an error name space Terratype not found, that is the main reason i thought i should put that model in my code might do the magic.

    ///<summary>
        /// Location
        ///</summary>
        [ImplementPropertyType("coordinates")]
        public Terratype.Models.Model Coordinates
        {
            get { return this.GetPropertyValue<Terratype.Models.Model>("coordinates"); }
        }
    

    This is my generated model, but it is throwing an error when referencing Terratype. What am i missing

  • Jonathan Richards 288 posts 1742 karma points MVP
    Jun 28, 2019 @ 10:39
    Jonathan Richards
    0

    Hi Advance Ngwarati

    If I had to make a guess, as your question isn't related to Terratype per se, but ModelsBuilder, is that you have more than one assembly and have so far have only referenced Terratype into the one that contains the Umbraco UI but not the assembly that you have ModelsBuilder running in. You need to install Terratype everywhere that you make references to it.

    If its not that above situation, then I will need to know lots more info like what Umbraco version, what ModelsBuilder (and how is it setup; API mode etc), how is your solution organised, Nuget or Package Manager, to be able to help further.

    Cheers

    Jonathan Richards

  • Advance Ngwarati 25 posts 127 karma points
    Jun 28, 2019 @ 11:11
    Advance Ngwarati
    0

    You are my life saver, I wasn't install the package in my Models Project. Now those errors goes away. But now the issue is when i try to get the location it is showing null value, but in backoffice the data is there. My View code is below

    if (brand.BrandLocation != null)
    {foreach (var location in brand.BrandLocation.Where(item => item != null))
    {
    @Html.Terratype(new Options {MapSetId = 1 },(Terratype.Models.Model)location.Coordinates)
    }
    

    }

    Back Office(Umbraco 7.10.4) This is my backoffice data Json Value

    What is weird is, the name the location i can access render it, but location is showing me null.

  • Jonathan Richards 288 posts 1742 karma points MVP
    Jun 28, 2019 @ 11:17
    Jonathan Richards
    0

    Advance Ngwarati

    Seeing in your code that you are casting location.Coordinates to (Terratype.Models.Model) is a large warning sign that location.Coordinates isn't actually of type Terratype.Models.Model. Its a little hard for me to figure out what it is from here, but I would focus your attention on that.

    Cheers

    Jonathan Richards

  • Advance Ngwarati 25 posts 127 karma points
    Jun 28, 2019 @ 11:19
    Advance Ngwarati
    0

    Thanks Jonathan,

    It worked like a charm, I should put error handling before rendering the map. Thanks again for the help.

Please Sign in or register to post replies

Write your reply to:

Draft