Copied to clipboard

Flag this post as spam?

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


  • Anders Brohus 194 posts 475 karma points
    May 29, 2018 @ 11:15
    Anders Brohus
    0

    Hi Our :)

    I have used the models builder for a long time, just with the DLL mode :)

    But then i read this article, https://24days.in/umbraco-cms/2016/getting-started-with-modelsbuilder/ and though the API mode was a better choise for me :)

    But the i keep getting the error "More than one type wants to be a model for content type content." when the "Builder.cs" file is included in the project, when i exclude them and build it works just fine :)

    Where do i make the mistake? :P

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    May 29, 2018 @ 11:47
    Nik
    101

    Hey Anders,

    First port of call, check that the old DLL has been deleted (the one Models Builder generated).

    Then, you need to update your views to use the new namespace. The API generates models in your own namespace not in the default ModelsBuilder namespace so all views need updated and the web.config in the Views folder :-)

    Give those a go and let us know if you still have issues.

    Nik

  • Anders Brohus 194 posts 475 karma points
    May 29, 2018 @ 11:50
    Anders Brohus
    1

    Oh yeah i should have told my self that i needed to delete the old one .. xD

    Thanks alot now it works :)

    Is there anyway to get the latest models on build or something like that? :)

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    May 29, 2018 @ 11:53
    Nik
    0

    Unfortunately not that I know of.

    To use the API version, as I understand it, you have to have the site running in debug mode for the API to be available. So you'd have to automate a process that spins up the website and runs it, then runs the custom VS tool (or it's equivalent code) to extract the latest models. Then you can re-compile the assembly.

    In theory, you should always have the latest code if you adjust your work process so that once you make any changes to doc types you run Models Builder custom tool again. That's probably your safer option.

    Nik

  • Anders Brohus 194 posts 475 karma points
    May 29, 2018 @ 11:55
    Anders Brohus
    1

    Okay, thanks alot :)

    I'm still trying to decide if we should use the API verison or DLL verison .. :)

    Becuase with the DLL version we always had to rebuild models i guess we don't need that as long as we always have the latest models :)

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    May 29, 2018 @ 11:58
    Nik
    0

    I would say go down the API route as it allows you to take advantage of the fact the models are partial classes and so you can override and extend them if you need to, (combining properties for example).

    I've managed to get into a point where I couldn't build a project because of DLL mode and my website and my Core project both wanting access to the models DLL, so have moved away from it since then.

    If you aren't doing anything complicated and aren't having separate projects DLL mode can work nicely though.

  • Anders Brohus 194 posts 475 karma points
    May 29, 2018 @ 12:01
    Anders Brohus
    1

    Nice thanks alot :)

    We do have seperate projects so maybe it's an good idea to use API mode :)

  • Madison James 31 posts 147 karma points
    Sep 25, 2018 @ 08:47
    Madison James
    0

    Nik, I've been using the API Mode and I have my site running. But I went to make some changes where I have a Master, then a Home that runs as Body, then a partial for the newest post on the home page.

    I'm running into an issue where the home model and the partial model seem to be clashing.

    Cannot bind source content type ModelsBuilder.APIMode.Models.Home to model type ModelsBuilder.APIMode.Models.MyBlogPost.

    I noticed you mention view webconfig needed to be changed. Could you elaborate please? I never saw anything about that when I set this up based on the 24 days in article

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Sep 25, 2018 @ 08:52
    Nik
    1

    Hi Madison,

    Do you want to spin up a new question on the forum for the binding issue you are getting? Happy to help though.

    Regarding the Web.Config change in the View folder, you don't have to change it, but I do to make things easier. In there I add the new namespace that my models are being generated under so I don't have to include it in my view every time I want to access it.

    By default the Web.Config contains a reference to (typing off the cuff so may not be 100%) Umbraco.Web.PublishedModels namespace, but we can remove this when using the API mode as our models don't exist there any more.

    So in your example Models are generating under ModelsBuilder.APIMode.Models I'd add that namespace instead :-) It's just an ease thing rather than a requirement.

    Nik

  • Madison James 31 posts 147 karma points
    Sep 25, 2018 @ 09:02
    Madison James
    0

    Thank you, When I looked at the config file I thought that was probably the case but wasn't sure.

    If I don't get this figured out pretty shortly I may start a separate question.

    I should have stated that this is 7.10.4 and I'm trying to do everything strongly typed. the problem started when I added the model to the partial.

    If you prefer I can start a different question.

    Thanks again

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Sep 25, 2018 @ 09:04
    Nik
    0

    Hi Madison,

    The reason for the fresh question is just so if other people come across the same issue they can find it :-) If you start the question now, I'll jump straight on it for you :-)

    In the question can you post the line where you are calling your partial view :-)

    Nik

  • Madison James 31 posts 147 karma points
    Sep 25, 2018 @ 09:24
    Madison James
    1

    Nik, thanks again I posted the question

    Cannot bind source content type ModelsBuilder.APIMode.Models.Home to model type ModelsBuilder.APIMode.Models.MyBlogPost

Please Sign in or register to post replies

Write your reply to:

Draft