By Matt Brailsford / @mattbrailsford
By Matt Brailsford / @mattbrailsford
By Lee Kelleher / @leekelleher
...an IPublishedContent model mapper for Umbraco
* based on the upcoming v0.9 release
public class MyModel {
public string Name { get; set; }
public string Url { get; set; }
}
MyView.cshtml / MyController.cs
var myModel = Model.Content.As<MyModel>();
[UmbracoProperties(Recursive = true)]
public class MyModel {
[UmbracoProperty("heading", "pageName")]
public string Name { get; set; }
public string Url { get; set; }
[DittoIgnore]
public string Ignore { get; set; }
}
MyMView.cshtml / MyController.cs
var myModel = Model.Content.As<MyModel>();
public class HelloAttribute : DittoProcessorAttribute {
public string Name { get; set; }
public override object ProcessValue() {
return "Hello " + Name; // Could be any type, from anywhere
}
}
MyModel.cs
public class MyModel {
[Hello(Name = "Matt")]
public string MyString { get; set; }
}
MyView.cshtml / MyController.cs
var myModel = Model.Content.As<MyModel>();
public class PagedContext : DittoProcessorContext {
public int Page { get; set; }
public int PageSize { get; set; }
}
[DittoProcessorMetaData(ValueType = typeof(object),
ContextType = typeof(PagedContext))]
public class NewsAttribute : DittoProcessorAttribute {
public override object ProcessValue() {
var ctx = Context as PagedContext;
return NewsService.GetLatestNews(ctx.Page, ctx.PageSize);
}
}
public class MyModel {
[News]
public IEnumerable<NewsItem> LatestNews { get; set; }
}
MyView.cshtml / MyController.cs
var ctx = new PagedContext { Page = 1, PageSize = 10 };
var myModel = Model.Content.As<MyModel>(processorContexts:new []{ ctx });
public class MyModel {
[UmbracoProperty("heading", "pageName", Order = 0)]
[Uppercase(Order = 1)]
public string Name { get; set; }
}
MyView.cshtml / MyController.cs
var myModel = Model.Content.As<MyModel>();
public class MyModel {
[DittoCache(CacheDuration = 300)]
[MyComplexData]
public IEnumerable<MyComplexData> Data { get; set; }
}
MyView.cshtml / MyController.cs
var myModel = Model.Content.As<MyModel>();
foreach(var item in myModel.Data){
...
}
* based on the upcoming v0.10 release
public class MyModel {
public string Name { get; set; }
public string Url { get; set; }
}
MyView.cshtml
@inherits DittoView<MyModel>
@Model.View.Name
public class NewsPageController : DittoController {
public override ActionResult Index(RenderModel model)
{
// Construct search context
var ctx = new PagedContext
{
Page = int.Parse("0" + Request.QueryString["p"]),
PageSize = int.Parse("0" + Request.QueryString["ps"])
};
// Register the context
RegisterProcessorContext(ctx);
// Continue to the page
return CurrentView(model);
}
}
NewsPage.cshtml
@inherits DittoView<MyModel>
@foreach(var newsItem in Model.View.LatestNews){
...
}
By Matt Brailsford / @mattbrailsford
By Lee Kelleher / @leekelleher