Last active
August 29, 2015 14:22
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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