Copied to clipboard

Flag this post as spam?

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


  • MuirisOG 382 posts 1284 karma points
    Jul 17, 2018 @ 12:38
    MuirisOG
    0

    ModelsBuilder with custom database tables

    I'm looking at ModelsBuilder posts here on the forum to see how it works.

    Is it possible to add models for custom database tables? We have a lot of data held outside Umbraco.

    Is it possible to pass more than one model to a single partial view macro page?

    Are there any good tutorials out there on ModelsBuilder?

    I've found a whole bunch of really useful links, including some on uHangout and 24 Days In, but does anyone know of a more recent practical example to show how it all works?

    Many thanks

    Muiris

  • Simon Napper 83 posts 253 karma points
    Jul 17, 2018 @ 13:34
    Simon Napper
    1

    I wouldn't of thought you could add custom tables to the models builder, I think it's pretty tightly coupled to Umbraco.

    For what your suggesting it sounds like you need to have a standard entity framework for your custom tables. You can then create some View Models to pass to your partials and populate them with what ever mix of data (i.e. EF or ModelsBuilder) that you need to populate your partial.

  • MuirisOG 382 posts 1284 karma points
    Jul 17, 2018 @ 13:56
    MuirisOG
    0

    Many thanks Simon

    I was going to try out adding my own custom models/classes into the App_Data/Models folder (e.g. as myModel.cs in addition to the autogenerated *.generated.cs classes), and then pass them to a View in the Partials folder (which in turn I was planning to render from a partial view macro - not exactly as I said above).

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Jul 17, 2018 @ 14:12
    Nik
    0

    Hi Muiris,

    You shouldn't look to add them to your AppData folder. If you are looking to include them in your site, I would advise either the AppCode folder or better yet, standard .CS files in a Models folder in the route of the site which can then be compiled (I'm assuming your site is a Web Application project in Visual Studio and not a WebSite project).

    Nik

  • MuirisOG 382 posts 1284 karma points
    Jul 17, 2018 @ 14:21
    MuirisOG
    0

    Hi Nik,

    We're coming from a WebForms site (which we migrated to Umbraco 7.5.14) where we have dozens of usercontrols of varying complexity.

    Our next step is to move to the latest Umbraco MVC environment, so we're thinking of using separate class libraries for some of the trickier stuff and compile them into DLLs, which I believe will make them available in our Views.

    I thought ModelsBuilder might have some useful helpful features.

  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Jul 17, 2018 @ 14:26
    Nik
    100

    Using a Class Library project is a good way to include things like models :-)

    Creating your own view models, and using something like Entity Framework, or PetaPoco (The latter of which is in Umbraco) could help with handling your custom data tables.

    As long as your web site/web application project references the Dll's you should be able to access the models/code in your views :-)

    Nik

  • MuirisOG 382 posts 1284 karma points
    Jul 17, 2018 @ 14:37
    MuirisOG
    1

    Many thanks Nik,

    It is incredibly reassuring to get feedback like this - it shows that we're on the right track.

    Thanks,

    Muiris

  • Harrison 42 posts 254 karma points
    Jul 20, 2018 @ 08:24
    Harrison
    1

    Few days late to the party, but from what it sounds like you want a custom view model that contains your data from your DB to render out in the Umbraco view?

    https://our.umbraco.com/documentation/reference/routing/custom-controllers

    This is a good starting point on how to create a custom view model with MVC, so in your controller you can gather all your custom data, and add it to a custom model to render out in your view.

  • MuirisOG 382 posts 1284 karma points
    Jul 20, 2018 @ 10:14
    MuirisOG
    0

    Many thanks Harrison,

    I'll have a look at this.

    I also found this tutorial from Paul Seal really helpful.

    https://codeshare.co.uk/blog/how-to-create-a-contact-form-in-umbraco-using-mvc-and-c/

Please Sign in or register to post replies

Write your reply to:

Draft