glass-mapper

How to Unit Test a GlassController Action which Uses Sitecore.Context.Item

梦想与她 提交于 2019-12-12 04:09:01
问题 I'm a sitecore developer and I want to create a sample sitecore helix unit testing project for testing out the logic you see in our "ArticleController" controller's Index() action method: public class ArticleController : GlassController { public override ActionResult Index() { // If a redirect has been configured for this Article, then redirect to new location. if (Sitecore.Context.Item.Fields[SitecoreFieldIds.WTW_REDIRECT_TO] != null && !string.IsNullOrEmpty(Sitecore.Context.Item.Fields

Sitecore using Glass mapper and MVC

会有一股神秘感。 提交于 2019-12-11 04:28:24
问题 Hi am using the Glass mapper in combination with Sitecore MVC. I created model below. using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace Test { using Glass.Mapper.Sc.Configuration.Attributes; [SitecoreType(AutoMap = true)] public class GlassTestModel { public virtual string Title { get; set; } } } this is my view @inherits Glass.Mapper.Sc.Web.Mvc.GlassView<Test.GlassTestModel> <div> <h2>Hello</h2> <h2>@Model.Title</h2> </div> I also tried this first

Sitecore glass editable cannot convert lambda expression

为君一笑 提交于 2019-12-11 04:08:42
问题 I'm using Sitecore 7.5, MVC 5.2 and Glass Mapper 3.2. When using Editable() in the renderings, the error below is shown in visual studio even though it renders properly when using the site and/or the page editor. Am I missing a reference or something? Error: "Cannot convert lambda expression to type 'System.Linq.Expressions.Expression>' because it is not a delegate type" View @using Sitecore.Mvc @using Sitecore.Mvc.Presentation @inherits Glass.Mapper.Sc.Web.Mvc.GlassView<Air.SitecoreModels

How to implement Sitecore Template inheritance with Glass Mapper

和自甴很熟 提交于 2019-12-11 01:44:20
问题 I've been trying to achieve the following with glass mapper but can't get it to work. I have a Home Page template which doesn't have any fields itself but inherits the following two templates: Navigation Template Fields: Navigation Title Meta Information Template Fields: Page Title, Meta Description I've created the corresponding interfaces / classes as follows: [SitecoreType(TemplateId = "{5BAB563C-12AD-4398-8C4A-BF623F7DBCDC}", AutoMap = true)] public interface INavigation { [SitecoreField

Sitecore Glass mapper GetItem<TypeName>(guid) always return null

帅比萌擦擦* 提交于 2019-12-10 18:24:25
问题 I saw a related question: Sitecore Glass Mapper always null But unfortunately it does not give a solution for my case. Here goes a code snippet: var db = Factory.GetDatabase("master"); var context = new SitecoreContext(); // the ID of Needed item var g = new Guid("{F21C04FE-8826-41AB-9F3C-F7BDF5B35C76}"); // just to test if it's possible to fetch item using db.GetItem var i = db.GetItem(new ID(g), Language.Current, Sitecore.Data.Version.Latest); // Grab item var t = context.GetItem<Article>(g

Could not resolve type name: Glass.Mapper.Sc.Pipelines.Response.GetModel, Glass.Mapper.Sc

岁酱吖の 提交于 2019-12-10 16:56:07
问题 I am trying to use Glass Mapper in my MVC - v4.0.30319 project in Sitecore - 7.1. Following are my Glass Mapper version which I have installed Glass Mapper version - 3.0.10.23 Glass.Mapper.Sc version - 3.2.0.39 Glass.Mapper.Sc.Mvc version - 3.2.0.34 when I installed Glass mapper Mvc from nuget it added a config file called (Glass.Mapper.Sc.Mvc) in App_Config -> include folder Content of the file is as follows <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/"> <sitecore>

Why should all Glass.Mapper fields be virtual?

你离开我真会死。 提交于 2019-12-10 16:20:31
问题 The Glass.Mapper documentation states: using Glass.Mapper.Sc.Configuration.Attributes; namespace Glass.Mapper.Sites.Sc.Models.Landing { public class HomePage { public virtual string Title { get; set; } public virtual string MainBody { get; set; } } } You can see that this class doesn't include any special markup however one important thing to remember when writing class with Glass.Mapper is to ensure that all your fields are marked as virtual . Glass.Mapper can automatically infer what data

How to render link with css class with Sitecore Glass Mapper

送分小仙女□ 提交于 2019-12-08 16:07:29
问题 I have the following link: <a class="btn btn-primary" href="#">View details »</a> How can I render the link with sitecore glass that it still keeps the css class? With the field renderer in sitecore you used to be able to pass the class along as additional parameters, how does this work with glass? This is what I have so far: @RenderLink(x => x.Link) This only renders the link without the class though. Any help appreciated. Thx. 回答1: You can also make a PageEditor enabled version like this

Glass.Mapper not applies additional parameters in BeginRenderLink method

佐手、 提交于 2019-12-02 07:11:09
问题 For Glass.Mapper BeginRenderLink described as method to render a link that should contain multiple HTML elements: http://glass.lu/docs/tutorial/sitecore/tutorial22/tutorial22.html What I'd like to add is custom attributes (class, style) to that link: <% using (BeginRenderLink(x => x.Image1Link, new NameValueCollection { { "class", "image-banner" }, { "style", string.Format("background-image: url({0})", Model.Image1.Src) } }, true)) { %> <span class="image-banner-wrapper"> <span class="image

Why isn't my Enumerable getting populated by Glass.Mapper?

孤人 提交于 2019-12-02 04:49:34
I'm totally confused as to why this isn't working. I have a class with a list of other classes as a property of it: public class Widget { .... public virtual IEnumerable<WidgetButton> Buttons { get; set; } } [SitecoreType(TemplateId = "{B615973D-59F6-437E-9827-BA3A40068C69}", AutoMap =true)] public class WidgetButton : BasePage { [SitecoreField] public virtual string Title { get; set; } } My sitecore item has a TreeListEx with one item in it: and I'm reading this item thus: Widget widgetTest = SitecoreContext.GetItem<Widget>(new Guid("{4FF5B96F-9606-4581-95F7-B6A7BAA4C28F}")); My Widget (