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

ZpqrtBnk Umbraco Models Builder

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

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.

About

Install the Visual Studio extension.
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"
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

And enjoy!

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...