加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-5 – 使用Glass Mapper的Sitecore 8可编辑字段

发布时间:2020-12-16 09:54:57 所属栏目:asp.Net 来源:网络整理
导读:出于某种原因,Visual Studio在视图中给出了此错误: Cannot convert lambda expression to type ‘System.Linq.Expressions.Expression’ because it is not a delegate type 另外,我没有关于lambda的intellisense. 我确保根据这篇文章将我的MVC版本降低到5.
出于某种原因,Visual Studio在视图中给出了此错误:

Cannot convert lambda expression to type
‘System.Linq.Expressions.Expression>’ because it is not a delegate
type

另外,我没有关于lambda的intellisense.

我确保根据这篇文章将我的MVC版本降低到5.1.0:

Sitecore glass editable cannot convert lambda expression

不幸的是,我没有直接在该帖子上发表评论所需的Stack Overflow点数.不幸的是,MVC版本解决方案对我不起作用.当我发布部署时,数据通过很好 – 编辑工作得很好 – 但我宁愿不要忽略红色波浪线和缺乏intellisense.

从新的Sitecore 8 / Visual Studio MVC应用程序设置,我跑:

更新包Glass.Mapper.Sc.CastleWindsor给我v3.3.1.26

然后我运行Install-Package Glass.Mapper.Sc.Mvc-5给我v3.3.1.48

我建立了一个模型

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Glass.Mapper.Sc;
using Glass.Mapper.Sc.Configuration.Attributes;

namespace myns.app.Models
{
    [SitecoreType]
    public class BaseContent
    {
        [SitecoreId]
        public virtual Guid Id { get; set; }

        [SitecoreField("Content Title")]
        public virtual string Title { get; set; }

        [SitecoreField("Summary Content")]
        public virtual string Summary { get; set; }

        [SitecoreField("Full Content")]
        public virtual string Content { get; set; }

        [SitecoreField("Content Image")]
        public virtual Glass.Mapper.Sc.Fields.Image ImagePath { get; set; }

    }
}

并且有一种工作的观点

@inherits Glass.Mapper.Sc.Web.Mvc.GlassView<myns.app.Models.BaseContent>

<div>
    <h4>BaseContent</h4>
    <hr />
    @Model.Title
    <p>@Editable(Model,x => x.Title)</p>
    <p>@Editable(Model,x => x.Summary)</p>
    <h5>content</h5>
    <p>@Editable(Model,x => x.Content)</p>
    <p>@RenderImage(Model,x => x.ImagePath)</p> 
</div>

提前感谢任何输入!

更新:
当我在webcore中提供的编译>程序集中注释掉以下三行时,问题似乎就消失了.不确定这是最好的事情:

<compilation defaultLanguage="c#" debug="false" targetFramework="4.5">
      <assemblies>
        <add assembly="System.Web.Abstractions,Version=4.0.0.0,Culture=neutral,PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Routing,PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Data.Linq,PublicKeyToken=B77A5C561934E089" />
        <add assembly="System.Web.Helpers,Version=3.0.0.0,PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.Mvc,Version=5.2.2.0,PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages,PublicKeyToken=31BF3856AD364E35" />
        <add assembly="System.Web.WebPages.Razor,PublicKeyToken=31BF3856AD364E35" />
        <!--add assembly="System.Web.Http,Version=5.1.0.0,PublicKeyToken=31BF3856AD364E35" /-->
        <!--add assembly="System.Web.Http.WebHost,PublicKeyToken=31BF3856AD364E35" /-->
        <!--add assembly="System.Net.Http.Formatting,PublicKeyToken=31BF3856AD364E35" /-->
      </assemblies>
    </compilation>

解决方法

在站点的web.config中的程序集节点中注释掉以下三行可以解决问题.

<!--add assembly="System.Web.Http,PublicKeyToken=31BF3856AD364E35" /-->
<!--add assembly="System.Web.Http.WebHost,PublicKeyToken=31BF3856AD364E35" /-->
<!--add assembly="System.Net.Http.Formatting,PublicKeyToken=31BF3856AD364E35" /-->

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读