我正在使用一種簡單的方法輸出圖像,並且如果介質類型具有連接到它的鏈接,它將充當鏈接。這種方法已經運行了好幾個月和幾個月,但突然有一位顧客抱怨說它不起作用。在Umbraco剃刀中的潛在字符串上使用string.IsNullOrEmpty
的全部我的剃鬚刀宏是這樣的:
@using umbraco.MacroEngines
@inherits umbraco.MacroEngines.DynamicNodeContext
@{
var topImageId = Model._topImage;
if (topImageId != null) {
var topImage = Library.MediaById(topImageId);
var linkId = topImage._link;
string cssStyle = string.Format("background-image:url({0});height:{1}px;", topImage.umbracoFile, topImage.umbracoHeight);
<div id="topImage"
@if(!string.IsNullOrEmpty(linkId)){
var tempNode = @Model.NodeById(linkId);
@Html.Raw(string.Format(" onclick=\"window.location.href='{0}'\"", @tempNode.Url));
cssStyle += " cursor: pointer;";
}
@Html.Raw(string.Format("style=\"{0}\"", cssStyle))
></div>
}
}
和它產生這兩種錯誤:
Error Loading Razor Script (file: Top Image) The best overloaded method match for 'string.IsNullOrEmpty(string)' has some invalid arguments at CallSite.Target(Closure , CallSite , Type , Object)
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at ASP._Page_macroScripts_general_topImage_cshtml.Execute() in d:\inetpub\wwwroot\friendtex.com\www\macroScripts\general\topImage.cshtml:line 15
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
at System.Web.WebPages.WebPage.ExecutePageHierarchy(IEnumerable`1 executors)
at System.Web.WebPages.WebPage.ExecutePageHierarchy()
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage)
at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage) 0.741249 0.004230
和
Error loading MacroEngine script (file: /general/topImage.cshtml, Type: ''
The best overloaded method match for 'string.IsNullOrEmpty(string)' has some invalid arguments
at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
我懷疑圖像本身是事業的根源,但媒體形象絕對是應有的,我看不出有什麼不同。爲了增加這個怪異因素 - 這個宏在任何其他圖像上都能很好地工作。失敗的圖像可以是found here
編輯:
出於某種奇怪的原因,如果我做GetType()
圖片道格拉斯建議,並返回一個Umbraco.MacroEngines.DynamicXml
對象,它的任何其他圖像上返回一個字符串。它只是越來越詭異和怪異。
第二個編輯:
我決定出去扔代碼,並利用該技術凱文·亨德里克斯建議重寫整個事情。現在突然之間,我沒有任何錯誤,它完美地工作。唯一不同的是幾個.ToString()
幾個地方。
有你在使用「下劃線」的理由鏈接的屬性名稱?你意識到這將遞歸搜索具有與其關聯的「鏈接」屬性的節點?你可以做的一件事就是輸出剃鬚刀引擎認爲屬性是的類型:'@ topImage._link.GetType()'。 –
不,我沒有意識到這一點。出於某種原因,當屬性名稱中的下劃線似乎在'getPropertyValue'不起作用時 –