Sitecore using Glass mapper and MVC

2019-07-11 01:57发布

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条回答
贼婆χ
2楼-- · 2019-07-11 02:42

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

查看更多
登录 后发表回答