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?
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.
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).
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).
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.
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 :-)
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?
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.
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
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.
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).
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
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.
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
Many thanks Nik,
It is incredibly reassuring to get feedback like this - it shows that we're on the right track.
Thanks,
Muiris
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.
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/
is working on a reply...