Skip to content

Instantly share code, notes, and snippets.

@jamiepollock
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamiepollock/ef59d769f840225c25f0 to your computer and use it in GitHub Desktop.
Save jamiepollock/ef59d769f840225c25f0 to your computer and use it in GitHub Desktop.
Gist using Umbraco Ditto and nested POCOs. Note: pre-rev4 this code worked with Ditto v.6 but not v.7.
using Our.Umbraco.Ditto;
using Umbraco.Core.Models;
namespace My.Website.ViewModels {
public class BasicPageViewModel {
public BasicPageViewModel(IPublishedContent content) {
Seo = content.As<SeoViewModel>();
}
[DittoIgnore]
public SeoViewModel Seo { get; set; }
}
public class SeoViewModel {
[UmbracoProperty("metaTitle")]
public string PageTitle { get; set; }
[UmbracoProperty("metaDescription")]
public string MetaDescription { get; set; }
[UmbracoProperty("metaKeywords")]
public string MetaKeywords { get; set; }
}
}
@model My.Website.ViewModels.BasicPageViewModel
@{
Layout = null;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>@Model.Seo.PageTitle</title>
</head>
<body>
<h1>My Website!</h1>
<p>Hello world.</p>
</body>
</html>
using My.Website.ViewModels;
using Our.Umbraco.Ditto;
using System.Web.Mvc;
using Umbraco.Web.Models;
using Umbraco.Web.Mvc;
namespace My.Website.Controllers {
public class HomePageController : RenderMvcController {
public ActionResult HomePage(RenderModel model) {
var viewModel = model.As<BasicPageViewModel>();
return View(viewModel);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment