【问题标题】:Sitecore Glass Mapper - GlassHtml.RenderImageSitecore 玻璃映射器 - GlassHtml.RenderImage
【发布时间】:2014-07-22 11:42:16
【问题描述】:

我注意到下面使用 GlassHtml.RenderImage 的教程,我们可以在其中指定图像的宽度和高度。

http://glass.lu/docs/tutorial/sitecore/tutorial16/tutorial16.html

<%= GlassHtml.RenderImage(Model, x => x.FeaturedImage) %>

我尝试使用 @Glass.Mapper.Sc.GlassHtml.RenderImage 使用此功能,但此 SC.GlassHTML 似乎没有 RenderImage

有人可以帮忙吗,我错过了什么?

谢谢。

【问题讨论】:

    标签: sitecore glass-mapper


    【解决方案1】:

    我尝试使用此功能 @Glass.Mapper.Sc.GlassHtml.RenderImage 但这个 SC.GlassHTML 没有 好像有RenderImage

    这样不行;您正在尝试访问一个实例方法,就好像它是静态的一样。
    您的视图需要从 Glass.Mapper.Sc.Web.Mvc.GlassView&lt;T&gt; 继承,因此它会在您的视图上公开 GlassHtml 方法。

    像这样配置你的/Views/web.config

    <system.web.webPages.razor>
      <host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
      <pages pageBaseType="Glass.Mapper.Sc.Web.Mvc.GlassView">
        <!-- snipped other lines... -->
    

    之后,您可以像这样在视图中访问GlassView 方法(调用GlassHtml 方法):

    @RenderImage(x =&gt; x.FieldName, new ImageParameters { Width = 80, Height = 80})

    【讨论】:

    • 或者如果配置更改太多,只需让这个特定视图使用@inherits Glass.Mapper.Sc.Web.Mvc.GlassView,然后使用 Ruud 的 RenderImage 代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多