SlideShare a Scribd company logo
#sugcon
#sitecore
Glass.Mapper.Sc
And Sitecore MVC
Michael Edwards
Hedgehog
@mikeedwards83
Serving Suggestions
MVC vs WebForms
@Editable(x=>x.Home.DeveloperName)
@Editable(x=>x.Home.DeveloperImage, new {height=40})
<%=Editable(x=>x.Home.DeveloperName) %>
<%=Editable(x=>x.Home.DeveloperImage, new {height=40}) %>
MVC vs WebForms
public partial class Featured : GlassUserControl<Featured>
public class RateBaconController :
GlassController
public virtual T GetRenderingParameters<T>()
public virtual T GetControllerItem<T>(bool
isLazy = false, bool inferType = false)
protected GlassController(ISitecoreContext
sitecoreContext, IGlassHtml glassHtml)
View Renderings (cshtml)
<mvc.getModel>
<processor
type="Glass.Mapper.Sc.Pipelines.Response.GetModel,
Glass.Mapper.Sc"/>
</mvc.getModel>
@inherits
Glass.Mapper.Sc.Web.Mvc.GlassView<Glass.Mapper.
Sc.Demo.Core.Models.Parts.Navigation>
MVC CSHTML
@inherits
Glass.Mapper.Sc.Web.Mvc.GlassView<Glass.Mapper.Sc.Demo.Models
.Controllers.RateBacon.RateBaconIndex>
MVC CSHTML
@RenderImage(x=>x.Item.RateBaconImage1)
@Editable(Model.Item, x=>x.SearchFor)
@using (BeginRenderLink(x => x.Home.DeveloperLink))
@GlassHtml.RenderImage(Model, x=>x.Item.RateBaconImage1)
@GlassHtml.Editable(Model.Item, x=>x.SearchFor)
@using (GlassHtml.BeginRenderLink(x => x.Home.DeveloperLink))
=
MVC CSHTML
@Editable(Model.Item, x=>x.SearchFor,
x=>string.Format(x.SearchFor, Model.Query))
@RenderImage(x=>x.Item.SearchResultIcon, new {width=56, @class="icon"})
@using (BeginRenderLink(x => x.Home.DeveloperLink, isEditable:true))
{
@Editable(x=>x.Home.DeveloperName)
@Editable(x=>x.Home.DeveloperImage, new {height=40})
}
MVC Controllers
private readonly ISitecoreContext _context;
private readonly ISitecoreService _master;
public CommentsController(
ISitecoreContext context,
ISitecoreService master)
{
_context = context;
_master = master;
}
ControllerBuilder.Current.SetControllerFactory(
new WindsorControllerFactory(container.Kernel));
MVC Model Binding
[HttpPost]
public ActionResult Index(CommentsIndex index)
{
CommentsIndex model = null;
CommentForm form = index.Form;
[SitecoreType(TemplateId = ICommentConstants.TemplateIdString)]
public class CommentForm
{
[TypeConverter(typeof(IndexFieldIDValueConverter))]
[IndexField("_group")]
[SitecoreId]
public virtual Guid Id { get; set; }
[SitecoreInfo(SitecoreInfoType.Name)]
public virtual string Name { get; set; }
Sitecore 7 Search / JSON
var index = ContentSearchManager.GetIndex("sitecore_master_index");
using (var context = index.CreateSearchContext())
{
var results = context.GetQueryable<CommentResult>()
.Where(x => x.CommentName.Contains(name)
|| x.CommentMessage.Contains(name))
.Take(10)
.ToList()
.Select(x =>
{
_context.Map(x);
return x;
});
return Json(results, JsonRequestBehavior.AllowGet);
}
Partials
@foreach (var child in Model.Featured)
{
{Html.RenderPartial("/Views/Sugnl/Partials/PageSpot.cshtml", child);}
}
@inherits
Glass.Mapper.Sc.Web.Mvc.GlassView<Glass.Mapper.Sc.Demo.Core.Models.sitec
ore.templates.Sugnl.Concrete.Landing>
PageSpot.cshtml
Unit Testing
[Test]
public void Rate_RatedImage1FirstRating_SetsRating()
{
//Arrange
var context = Substitute.For<ISitecoreContext>();
var service = Substitute.For<ISitecoreService>();
var controller = new RateBaconController(context, service);
var itemId = Guid.NewGuid();
var ratingNumber = 1;
var rating = 4;
var item = new RateBacon();
context.GetItem<RateBacon>(itemId).Returns(item);
service.Save(item);
//Act
var result = controller.Rate(itemId, ratingNumber, rating);
//Assert
Assert.AreEqual(rating, item.RateBaconRate1);
Assert.AreEqual(1, item.RateBaconCount1);
}
Unit Testing
public RateBaconController(
ISitecoreContext context,
ISitecoreService service
):base(context, new GlassHtml(context))
{
_service = service;
}
Glass.Mapper.Sc.Razor
• It’s Razor Syntax
• Works with WebForms
• Works with MVC
• Works with Glass
• Sweet
Glass.Mapper.Sc.Razor
@inherits Glass.Mapper.Sc.Razor.Web.Ui.TypedTemplate<
Glass.Mapper.Sc.Demo.Core.Models.Parts.Navigation>
<div class="navigation-bar-content">
<a href="/" class="element">
@RenderImage(x=>x.Home.HomeSiteLogo, new {width=24})
@Model.Home.HomeSiteName
</a>
<span class="element-divider"></span>
<a class="pull-menu" href="#"></a>
Glass.Mapper.Sc.Razor
• Different templates
• Typed
• Behind
• Dynamic
• Not compatible with MVC chstml
• Not compatible with controllers
www.glass.lu
@mikeedwards83
Find me near one of these
Thank
you
19

More Related Content

What's hot (20)

PPT
Spring MVC 3.0 Framework
Ravi Kant Soni ([email protected])
 
PPTX
Asp.Net MVC 5 in Arabic
Haitham Shaddad
 
PPTX
Simple mvc4 prepared by gigin krishnan
Gigin Krishnan
 
PPTX
ASP.NET Routing & MVC
Emad Alashi
 
ODP
Design Patterns in ZK: Java MVVM as Model-View-Binder
Simon Massey
 
PPTX
Single page application 03
Ismaeel Enjreny
 
PPTX
Spring MVC
Emprovise
 
PPS
Introduction To Mvc
Volkan Uzun
 
PPTX
Planbox Backbone MVC
Acquisio
 
PDF
SpringMVC
Akio Katayama
 
PDF
AngularJS Basics
Nikita Shounewich
 
PDF
當ZK遇見Front-End
祁源 朱
 
PDF
iOS viper presentation
Rajat Datta
 
PPTX
Angular Data Binding
Jennifer Estrada
 
PPTX
React JS .NET
Jennifer Estrada
 
PPTX
Angular js presentation at Datacom
David Xi Peng Yang
 
PPTX
Sexy Architecting. VIPER: MVP on steroids
Dmytro Zaitsev
 
PPTX
Angularjs Basics
Jayantha Sirisena
 
PPTX
Getting Started with Angular JS
Akshay Mathur
 
PDF
Backbone js
Rohan Chandane
 
Spring MVC 3.0 Framework
Ravi Kant Soni ([email protected])
 
Asp.Net MVC 5 in Arabic
Haitham Shaddad
 
Simple mvc4 prepared by gigin krishnan
Gigin Krishnan
 
ASP.NET Routing & MVC
Emad Alashi
 
Design Patterns in ZK: Java MVVM as Model-View-Binder
Simon Massey
 
Single page application 03
Ismaeel Enjreny
 
Spring MVC
Emprovise
 
Introduction To Mvc
Volkan Uzun
 
Planbox Backbone MVC
Acquisio
 
SpringMVC
Akio Katayama
 
AngularJS Basics
Nikita Shounewich
 
當ZK遇見Front-End
祁源 朱
 
iOS viper presentation
Rajat Datta
 
Angular Data Binding
Jennifer Estrada
 
React JS .NET
Jennifer Estrada
 
Angular js presentation at Datacom
David Xi Peng Yang
 
Sexy Architecting. VIPER: MVP on steroids
Dmytro Zaitsev
 
Angularjs Basics
Jayantha Sirisena
 
Getting Started with Angular JS
Akshay Mathur
 
Backbone js
Rohan Chandane
 

Recently uploaded (20)

PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
PPTX
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
PPTX
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Reverse Engineering of Security Products: Developing an Advanced Microsoft De...
nwbxhhcyjv
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
From Code to Challenge: Crafting Skill-Based Games That Engage and Reward
aiyshauae
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
July Patch Tuesday
Ivanti
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
CIFDAQ Market Insights for July 7th 2025
CIFDAQ
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Complete JavaScript Notes: From Basics to Advanced Concepts.pdf
haydendavispro
 
WooCommerce Workshop: Bring Your Laptop
Laura Hartwig
 
UiPath Academic Alliance Educator Panels: Session 2 - Business Analyst Content
DianaGray10
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Using FME to Develop Self-Service CAD Applications for a Major UK Police Force
Safe Software
 
Ad

SUGCon 2014 Sitecore MVC

Editor's Notes

  • #6: Show /sitecore/layout/Renderings/Sugnl/Parts/Navigation Show Navigation.cshtml Show Navigation.cs Show http://sugnl.glass.demo
  • #9: Show the search page in edit mode and normal mode.
  • #13: HomePageSpots.cshtml