The Conspiracy
The Conspiracy

Reputation: 3953

Storing viewmodels in Umbraco project

I installed Umbraco 7 and expected it to have "Models", "Controllers" and "Views" folders. However, there's only the "Views" folder.

I searched through several tutorials that include creating a Model, but none tells me where to put it.

So could you please explain where to put an Umbraco Model file?

Upvotes: 0

Views: 808

Answers (2)

Tim
Tim

Reputation: 4257

By default, Umbraco doesn't have models in the Models folder in the traditional MVC sense. All content is returned as a property on the Umbraco ViewModel, accessed via Model.Content, which is the current page that you are viewing. This also gives you access to the parents, ancestors and children of the current page.

If you want to have strongly typed models, you can still do that, you will just have to either code something from scratch or use one of the existing projects for mapping Umbraco content to Models.

A good place to start on model mapping is Ditto: project page

If you want to find out more about the way the models etc work, I recommend reading the documentation on MVC tempting n Umbraco some of it is slightly out of date, but it should give you the basics.

Finally, if you want to check out more advanced stuff, like custom view models and routing, check out the Hybrid Framework which has some excellent examples of how to do that kind of stuff!

Hope that helps!

Upvotes: 2

Sébastien Richer
Sébastien Richer

Reputation: 1691

You can easily use /Models/, personally I always setup all of my custom code in a /Code/ folder. It's easier for me to find all I need as I work on a project and when I start a new one and I want to recycle some of my old code.

I mostly use Surface Controllers, so I have a /SurfaceControllers/ folder also.

I don't really do controller highjacking so I'm not sure about those.

Hope this helps!

Upvotes: 1

Related Questions