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 line

@model Test.GlassTestModel

and this one

@inherits System.Web.Mvc.WebViewPage<Test.GlassTestModel>

I created a view rendering in Sitecore. configured the model to use above. When I render the view the model fields don't get filled. When I test in a controller I use for other controller view like below:

ISitecoreContext ctx = new SitecoreContext();
var item = ctx.GetCurrentItem<Test.GlassTestModel>();

I do get the title field. Any ideas?


回答1:


I migrated my solution to V4 of the Glass.Mapper package. This works. With V3 I can't get the automapping to work.



来源:https://stackoverflow.com/questions/32737864/sitecore-using-glass-mapper-and-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!