Copied to clipboard

Flag this post as spam?

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


  • Craig 34 posts 270 karma points
    Sep 24, 2016 @ 15:06
    Craig
    0

    ViewModel class to inherit from ContentModel

    Hi,

    I've got my Umbraco install setup with ModelsMode set to dll and everything works fantastically well.

    My issue is that for one of my pages (a Contact Form) I want to create a ViewModel that will inherit from my ContentModels.Content class allowing me to extend what I have stored within the Umbraco model with information specific to the Contact Form. However I can't figure out what namespace I need to import in order to be able to write:

    public class ContactFormViewModel : ContentModels.Contact
    

    Is this possible? I presume it must be

  • Marc Goodson 2126 posts 14218 karma points MVP 8x c-trib
    Sep 25, 2016 @ 09:50
    Marc Goodson
    100

    Hi Craig

    The Developer section of Umbraco has a Models Builder tab that confirms all the current settings of the Models Builder on your site, including the name of the Models namespace:

    enter image description here

    if that is what you are after?

    You can change the name of the namespace in the web.config of your site by setting an app setting value for "Umbraco.ModelsBuilder.ModelsNamespace"

    regards

    Marc

  • Craig 34 posts 270 karma points
    Sep 25, 2016 @ 13:14
    Craig
    0

    Thanks Marc. I'd actually noticed the namespace and included the namespace within my model file but couldn't work out why Visual Studio couldn't see any of the models which I had presumed were going to be available. I've configured the ModelsMode to "Dll" which I had presumed would add a reference to the Umbraco.Web.PublishedContentModels dll. To get around this I've included the generated class file from AppData in my solution. Is there a better way to do this via a reference?

  • Marc Goodson 2126 posts 14218 karma points MVP 8x c-trib
    Sep 25, 2016 @ 23:25
    Marc Goodson
    0

    Hi Craig

    It depends a little on your project structure, but I tend to run ModelsBuilder in AppData mode, and then include the generated files in the app data folder in the Visual Studio solution, then you get intellisense on the model classes, and they are easy to extend via inheritence, but mainly it's easy to see in source control what changed when.

    But if you have multiple projects in the solution that need to reference the models then Dll mode makes it easier to share the dll and avoid circular references.

    regards

    Marc

Please Sign in or register to post replies

Write your reply to:

Draft