Error Loading Razor Script (file: Forside Teasers) Object reference not set to an instance of an object. at Umbraco.Core.Dynamics.DynamicXml.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result) at umbraco.MacroEngines.DynamicXml.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result) at CallSite.Target(Closure , CallSite , Object , String ) at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at ASP._Page_macroScripts_forsideTeasers_cshtml.Execute() in d:\web\localuser\lykkenvej5.dk\public_html\macroScripts\forsideTeasers.cshtml:line 49 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,488778
0,069603
macro
Error loading MacroEngine script (file: forsideTeasers.cshtml, Type: '' Object reference not set to an instance of an object. at Umbraco.Core.Dynamics.DynamicXml.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result) at umbraco.MacroEngines.DynamicXml.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result) at CallSite.Target(Closure , CallSite , Object , String ) at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1) at ASP._Page_macroScripts_forsideTeasers_cshtml.Execute() in d:\web\localuser\lykkenvej5.dk\public_html\macroScripts\forsideTeasers.cshtml:line 49 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) at umbraco.macro.loadMacroScript(MacroModel macro) at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
warp a link on div
umbraco 4.11.5
In Razor
get a link around the div
this i my div
<div class="column @strtw paddingrb16"><div class="transition @strfyld"><img class="rundkanter" src="@strdamp"/></div><div class="textoverteasers @strtw"><div class="padding5"><span class="sortlilleoverskrift">@stroverskrift</span><br/><div class="padding10"><span class="teasertext">@strtekst</span></div></div></div></div>
how to get a link around the div
<a href="mylink"><div class="column @strtw paddingrb16"><div class="transition @strfyld"><img class="rundkanter" src="@strdamp"/></div><div class="textoverteasers @strtw"><div class="padding5"><span class="sortlilleoverskrift">@stroverskrift</span><br/><div class="padding10"><span class="teasertext">@strtekst</span></div></div></div></div></a>
Hi Brian
If I understand your post correctly I suppose that the only thing you're missing above is to actually get the link written in the href attribute.
I believe you should be able to use this @umbraco.library.NiceUrl(Model.Id)
<a href="@umbraco.library.NiceUrl(Model.Id)"><!--Your div here--></a>
Hope this helps.
/Jan
sorry I was not fully awake when I wrote this
I forgot to write that it is in a loop and that I would only have a link if linkon = 1
Hi Brian
Ok, do you have any Razor setup currently? Or should we start from the bottom? :)
/Jan
Hi Jan
yes and here is my script
@using umbraco;
@using umbraco.MacroEngines;
@{
var list = @Model.teaser;
var linkurl = "";
var link = "";
var strdamp = "";
var strtw = "";
var linkon = "";
var linkonhtml = "";
var testlink="";
foreach (var item in list)
{
var strimg = Library.MediaById(item.umbracofile);
var strimge = @strimg.url;
var strtekst = item.bodyText;
var stroverskrift = item.overskrift;
var strfyld = item.fyld;
/* bestemmer størrelse på teaser */
if (@strfyld == "column1x1"){strtw = "columnb1";strdamp = strimge.Replace(".jpg","_column1x1.jpg");}
if (@strfyld == "column1x2"){strtw = "columnb2";strdamp = strimge.Replace(".jpg","_column1x2.jpg");}
if (@strfyld == "column2x1"){strtw = "columnb1 columnh2";strdamp = strimge.Replace(".jpg","_column2x1.jpg");}
if (@strfyld == "column2x2"){strtw = "columnb2 columnh2";strdamp = strimge.Replace(".jpg","_column2x2.jpg");}
if (@strfyld == "column2x3"){strtw = "columnb3 columnh2";strdamp = strimge.Replace(".jpg","_column2x3.jpg");}
if (@strfyld == "column2x4"){strtw = "columnb4 columnh2";strdamp = strimge.Replace(".jpg","_column2x4.jpg");}
/* bestemmer størrelse på teaser */
if(item.link.contentPicker.GetType() == typeof(DynamicXml) &&item.link.contentPicker.Any()){
link = @Model.NodeById(item.link.contentPicker.content).url;
linkon = "1";
}
<div class="column @strtw paddingrb16"><div class="transition @strfyld"><img class="rundkanter" src="@strdamp"/></div><div class="textoverteasers @strtw"><div class="padding5"><span class="sortlilleoverskrift">@stroverskrift</span><br/><div class="padding10"><span class="teasertext">@strtekst</span></div></div></div></div>
}
}
Hi Brian
Ok, in regards to the above code I think you should try and do this instead in the part where you fetch the link and have your div.
@if(item.hasValue("link")){
<a href="@item.niceUrl("link")">
<div class="column @strtw paddingrb16"><div class="transition @strfyld"><img class="rundkanter" src="@strdamp"/></div><div class="textoverteasers @strtw"><div class="padding5"><span class="sortlilleoverskrift">@stroverskrift</span><br/><div class="padding10"><span class="teasertext">@strtekst</span></div></div></div></div></a>
}else{
<div class="column @strtw paddingrb16"><div class="transition @strfyld"><img class="rundkanter" src="@strdamp"/></div><div class="textoverteasers @strtw"><div class="padding5"><span class="sortlilleoverskrift">@stroverskrift</span><br/><div class="padding10"><span class="teasertext">@strtekst</span></div></div></div></div>
}
I guess this should work - hope it makes sense :)
/Jan
Hi Jan
I get an error
at umbraco.MacroEngines.DynamicXml.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result)
at CallSite.Target(Closure , CallSite , Object , String )
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at ASP._Page_macroScripts_forsideTeasers_cshtml.Execute() in d:\web\localuser\lykkenvej5.dk\public_html\macroScripts\forsideTeasers.cshtml:line 49
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)
Object reference not set to an instance of an object.
at Umbraco.Core.Dynamics.DynamicXml.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result)
at umbraco.MacroEngines.DynamicXml.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result)
at CallSite.Target(Closure , CallSite , Object , String )
at System.Dynamic.UpdateDelegates.UpdateAndExecute2[T0,T1,TRet](CallSite site, T0 arg0, T1 arg1)
at ASP._Page_macroScripts_forsideTeasers_cshtml.Execute() in d:\web\localuser\lykkenvej5.dk\public_html\macroScripts\forsideTeasers.cshtml:line 49
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)
at umbraco.macro.loadMacroScript(MacroModel macro)
at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
is working on a reply...