我有一個Sitecore的sublayout返回一個字符串,它看起來像這樣的背後的C#代碼的函數:斜槓在Sitecore的從字符串中缺少Sublayout
public string getProductTitle()
{
Item productItem = itemHelper.GetItemByPath(currentItemPath);
Sitecore.Data.Fields.ImageField imgField = ((Sitecore.Data.Fields.ImageField)productItem.Fields["Logo"]);
if (imgField.Value != "")
{
return "<sc:Image CssClass=\"product-image ng-scope\" Field=\"Logo\" runat=\"server\" />";
}
string productTitle = "";
productTitle = productItem["Produkt Titel"];
return "<div class=\"product-name ng-binding ng-scopen\" ng-if=\"!currentProduct.imageNameHome\">" + productTitle + "</div>";
}
而在ASCX我把這個功用:
<%= getProductTitle() %>
的問題是,到底這是我在運行時獲得的HTML:
"<sc:Image CssClass=\"product-image ng-scope\" Field=\"Logo\" runat=\"server\" >";
/最後缺失,這打破了整條線,並且沒有顯示圖像。該
我也試過這樣:
string a = WebUtility.HtmlEncode("<sc:Image CssClass=\"product-image ng-scopen\" Field=\"Logo\" runat=\"server\" />");
return WebUtility.HtmlDecode(a);
這:
return @"<sc:Image CssClass=""product-image ng-scopen"" Field=""Logo"" runat=""server"" />";
具有相同的結果。
我在這裏錯過了什麼嗎?我怎樣才能解決這個問題?
我得到這個工作要感謝你們倆。但是現在我遇到了另一個相關的問題:我將如何在中繼器中使用它?在後面的代碼中,我得到了錯誤消息** this.imageRelatedTitle.Visible = true; **沒有定義imageRelatedTitle。我有一箇中繼器中帶有此Id的asp:placeholder。 – SpaceJump
只是計算出來:_var imageRelatedTitle = e.Item.FindControl(「imageRelatedTitle」)作爲PlaceHolder; _在ItemDataBound函數中。 – SpaceJump
很高興它正在制定@SpaceJump! –