Created
April 1, 2012 17:58
-
-
Save mikeedwards83/2277395 to your computer and use it in GitHub Desktop.
GlassUserControl demo of a page editor user control
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 System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web; | |
using System.Web.UI; | |
using Glass.Sitecore.Mapper; | |
using System.Linq.Expressions; | |
namespace Glass.Demo.Application.Web.Controls | |
{ | |
public class GlassUserControl<T> : UserControl | |
{ | |
public GlassUserControl() | |
{ | |
SitecoreContext = new SitecoreContext(); | |
GlassHtml = new Glass.Sitecore.Mapper.GlassHtml(SitecoreContext); | |
} | |
public ISitecoreContext SitecoreContext { get; set; } | |
Glass.Sitecore.Mapper.GlassHtml GlassHtml { get; set; } | |
public T Model { get; set; } | |
public string Field(Expression<Func<T, object>> field) | |
{ | |
if(field == null) throw new NullReferenceException("No field set"); | |
if (Model == null) throw new NullReferenceException("No model set"); | |
try | |
{ | |
var result = GlassHtml.Editable<T>(field, Model); | |
return result; | |
} | |
catch (Exception ex) | |
{ | |
return ex.Message; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment