I posted this a couple days ago but may have not explained it well.
I have a searchresults.cshtml macroscript tied to a macro embedded on a page. It successfully returns search results, but if the metaDescription field is null for an item, then I get an error on the page "Error loading MacroEngine script (file: SearchResults.cshtml) " Rather than going through all my site pages and assets and verifying there is a metaDescription, I'd like to write an if statement saying something like this
Thanks Dennis, I would think those would work right? Not sure what's going on here. Both of them throw the same error on the page:
Error loading MacroEngine script (file: Search_Results.cshtml)
Not sure what the deal is or how to go about fixing it. Right now, I'm just not showing the metaDescriptions, but it would be nice to have logic in there showing that info if it exists.
May I ask what exact version of 7 you're using? And do you get any further details if you look in the trace log in /app_data/logs? Watch for any message marked with "error" that might relate to this.
2014-11-11 13:31:12,402 [5] WARN umbraco.macro - [Thread 7] Error loading MacroEngine script (file: SearchResults.cshtml, Type: ''. Exception: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.getItem(TKey key)
at ASP.PagemacroScriptsSearchResultscshtml.Execute() in c:\inetpub\GHXroot\MacroScripts\SearchResults.cshtml:line 61
at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
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)
at umbraco.macro.loadMacroScript(MacroModel macro)
at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
I say "Kind of", because it will diplay the description, but if it's trying to evaluate a record what doesn't have a value for that then it throws that error.
If statement Syntax
I posted this a couple days ago but may have not explained it well. I have a searchresults.cshtml macroscript tied to a macro embedded on a page. It successfully returns search results, but if the metaDescription field is null for an item, then I get an error on the page "Error loading MacroEngine script (file: SearchResults.cshtml) " Rather than going through all my site pages and assets and verifying there is a metaDescription, I'd like to write an if statement saying something like this
This statement and many similar ones still causes the same error..Any blaring obvious ideas or help with the correct syntax for this stament? thanks
Hi Brian,
What if you do something like this.
And I think that you could access the value of the field like this
Hope this helps,
/Dennis
Hi Dennis, thanks so much for the quick reply..Just tried that (even swapped out the actual value in the
tag with just 'test' text and I get this: Error loading MacroEngine script (file: Search_Results.cshtml)
Also that doesn't work, just using the @page.MetaDescription..If this helps at all, below is the entire macropartial page..
Okay does it any difference if you do it this way.
Or you could try:
Hope this helps,
/Dennis
Thanks Dennis, I would think those would work right? Not sure what's going on here. Both of them throw the same error on the page: Error loading MacroEngine script (file: Search_Results.cshtml)
Not sure what the deal is or how to go about fixing it. Right now, I'm just not showing the metaDescriptions, but it would be nice to have logic in there showing that info if it exists.
Hi Brian
May I ask what exact version of 7 you're using? And do you get any further details if you look in the trace log in /app_data/logs? Watch for any message marked with "error" that might relate to this.
/Jan
Hi Jan,
Umbraco version 7.1.6 assembly: 1.0.5350.25714
2014-11-11 13:31:12,402 [5] WARN umbraco.macro - [Thread 7] Error loading MacroEngine script (file: SearchResults.cshtml, Type: ''. Exception: System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary. at System.Collections.Generic.Dictionary`2.getItem(TKey key) at ASP.PagemacroScriptsSearchResultscshtml.Execute() in c:\inetpub\GHXroot\MacroScripts\SearchResults.cshtml:line 61 at System.Web.WebPages.WebPageBase.ExecutePageHierarchy() 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) at umbraco.macro.loadMacroScript(MacroModel macro) at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
Another odd thing I just noticed is that the following if statement kind of works (if the results actually have value for metaDescription)
I say "Kind of", because it will diplay the description, but if it's trying to evaluate a record what doesn't have a value for that then it throws that error.
is working on a reply...