使用sitecore的Srcset

时间:2017-11-02 10:06:25

标签: asp.net-mvc html5 sitecore sitecore8

我有1176px X 820px图像。它应该使用sitcore srcset选项渲染1140px X 290px。我使用以下代码但它无法正常工作。

Dictionary<int, int> wList = new Dictionary<int, int>() { { 150, 768 }, { 230, 1024 }, { 290, 2000 } };

var withQuerystring = string.Empty;

foreach (var v in wList)
{
    var s = Model.ASpot1Image.Src + "?h=" + v.Key;
    var r = Sitecore.Resources.Media.HashingUtils.ProtectAssetUrl(s);
    withQuerystring = withQuerystring + r + " " + v.Value + "w,";
}

withQuerystring = withQuerystring.TrimEnd(',');

if (Model.ASpot1ImageUrl != null)
{
    using (BeginRenderLink(m => Model.ASpot1ImageUrl, isEditable: true))
    {
       @RenderImage(m => m.ASpot1Image, new { @class = "img-responsive", 
       @srcset = @withQuerystring }, isEditable: true)

0 个答案:

没有答案