Is there a way for me to define a model for a partial view in Umbraco instead of source?
l
I'm new to Umbraco, so it's entirely possible I'm being silly. I'm trying to recreate an existing website which is pure Razor Pages/MVC. Is there a way for me to define a model for a partial view that I created in Umbraco without creating a C# class and republishing my entire project?
j
Hey @Licht, welcome! It depends what you mean by define a model. C# is statically typed, so the type for the model needs to exist at compile time. If it's a custom type, i.e. a model of your creation with properties that you define, then you'll need your own class for that and, yes, republishing the project. There are ways to avoid this, using things like the viewdata dictionary, but they can get tricky to manage.
l
That's unfortunate since I can do all the Razor in Umbraco. I guess I'll just need to suck it up. The models don't change that often.
Thank you.
m
https://docs.umbraco.com/umbraco-cms/reference/templating/modelsbuilder Models builder in something other than PureLive will give you classes for you doc type definitions which you can work with in VS I'd suggest one of the AppData options. There is also a couple of options around the path if you want to change their location
But no way around rebuilding
l
Hm maybe I should put all my views in Git. But I didn't and to do that so I could rapidly edit them. But it is very easy to push updates to Azure App Service anyways.
If the models are in Git it's hard to feel like it's ok to draw the line between the two.
I'm also in Umbraco compiler hell right now
j
I'd definitely recommend committing your views. It can be helpful to have that version history. We don't usually allow view editing on the production system but YMMV
l
I wonder up moving all my views in the end for that reason. I didn't want to make an oops in production and potentially not even realize it.
What's sketchy is when document types have DB backed models.
I'm not pushing my DB to production when I publish. Maybe I should.
j
Have a look at uSync
It serialses things from the Umbraco database to disk. You can use those files to synchronise settings (doctypes etc.) between your local development environment and wherever your deploying too.
l
Is there an advantage to this over using SQLite and publishing that to production with the binaries?
j
SQLite isn't really suitable for production use, it only supports a single writer and gets locked up under concurrent load,
l
I'm happy I asked. I've never used SQLite for anything before.
j
It's generally a good idea to separate the "content" in the database from the code/schema too. Most devs won't want to push content to the server, just code and uSync settings files - then periodically get the content from the live database as necessary for wokring on the site (either uSync content files, or a db exoort depedning on how you want to work).
If you're just starting out, @CodeSharePaul 's video series on getting started with Umbraco v10 gives good overview of a "normal" development setup for Umbraco

https://www.youtube.com/watch?v=qEZtjxDEK8g&list=PL90L_HquhD-81xTOCLLJZLl1roU6hXPhp

l
I'll check it out. Thank you for your assistance.
2 Views