Skip to content
Stephan edited this page Oct 30, 2013 · 24 revisions

ZpqrtBnk Umbraco Models Builder Copyright (C) Pilotine - ZpqrtBnk 2013
Distributed under the MIT license

About

An experimental tool that can generate a complete set of strongly-typed published content models for Umbraco 6.2+ to be used in the MVC views. Either from the Umbraco UI, from the command line, or from Visual Studio.

DISCLAIMER: THIS CODE IS UNSTABLE AND FOR INFO ONLY !!

It runs on a modified 6.2.0 Umbraco version so it will not compile on the stock code from Umbraco's repo.

Usage

Website integration

This is for people not wanting to use Visual Studio. And it requires that the Umbraco website is running in FullTrust mode. Deploy the Zbu.ModelsBuilder.AspNet project to the Umbraco bin directory, and copy the GeneraleModelsDashboard.ascx wherever you want. Declare that ascx in the dashboard.config file.

Then, when you go to that dashboard, you can click on a button to generate models. Models file go to ~/App_Data/Models, while a special build.models file goes to ~/App_Core. Removing ~/App_Core/build.models disables the models entirely. Note that generating the models imply touching build.models, which in turn imply restarting the app domain.

Visual Studio extension

This is the preferred solution for people running Visual Studio. Install the Visual Studio extension. Then...
Create a file named "Foo.cs" in your solution.
Set the "Custom Tool" for that file to "ZbuModelsBuilder"
Set the "Custom Tool Namespace" for that file to "MyModels" or whatever you want
Save the file...

And it will connect to your Umbraco instance, and generate, underneath that file, NewsItem.generated.cs, corresponding to your NewsItem content type, looking like:

namespace MyModels
{
  public partial class NewsItem : PublishedContentModel
  {
    public string Title { get { return this.GetPropertyValue<string>("title"); } }
    public IHtmlString BodyText { get { return this.GetPropertyValue<IHtmlString>("bodyText"); } }
  }
}

And then you can create an MVC view such as

@inherits UmbracoViewPage<NewsItem>
@using MyModels
<h1>@Model.Title</h1>
@Model.BodyText

Next

Should document how to customize models, exclude types and properties...

Well -- it won't work for you, because a few stuff are missing or hard-coded (connection string...) at the moment. Plus it requires a version of 6.2.0 that has a few things made public instead of internal.

But... time will come...