Everything working great. Then I put the templates up on a staging environment and I get the following error on every single @Model reference:
Cannot perform runtime binding on a null reference.
This is a bummer. Seems like it must be a configuration issue. Can anyone think of a reason why I may not be able to "speak" Razor in my templates? Code in the page is identical to that on my local instance.
Actually I am running in WebForms mode because some other developers on the project are using umbraco:item tags -- however, on all our local instances we are able to use both techniques in our templates. I have umbraco:item tags and Razor macros in the same page and it's working fine. I am not using a URL picker but just a textfield (it's an external link), but I went with your idea and syntax:
@{
if (CurrentPage.HasValue("ctaButtonLinkUrl")){
<a href="@CurrentPage.ctaButtonLinkUrl">@CurrentPage.ctaButtonText</a>
}
}
And I get:
The name 'CurrentPage' does not exist in the current context.
Well, the proof is in the pudding -- it is "possible to add Razor directly into the templates." I'm doing it locally. The *.cshtml macros only don't work on this server. I suspect I'll get the same error if using a partial view but I will try it later! Thanks again for staying with me on this! Cheers.
Razor Not Working Globally
Hi,
Developed a site locally (7.3) and I'm doing all my nullchecks and plugging in all my template values using Razor macros a la:
Everything working great. Then I put the templates up on a staging environment and I get the following error on every single @Model reference:
This is a bummer. Seems like it must be a configuration issue. Can anyone think of a reason why I may not be able to "speak" Razor in my templates? Code in the page is identical to that on my local instance.
Thanks,
Garrett
Hi Garrett,
You are running Umbraco 7.3, did you run in MVC mode or in WebForms mode. If you are running in MVC mode, then you should try something like this.
I assume that you are using a content picker to pick the url to the page.
Hope this helps,
/Dennis
Thanks for your speedy reply, Dennis.
Actually I am running in WebForms mode because some other developers on the project are using umbraco:item tags -- however, on all our local instances we are able to use both techniques in our templates. I have umbraco:item tags and Razor macros in the same page and it's working fine. I am not using a URL picker but just a textfield (it's an external link), but I went with your idea and syntax:
And I get:
Thanks again for your help. Any other ideas?
//Garrett
Hi Garrett,
When you are running in WebForms, as I remember it´s not possible to add Razor directly into the templates.
Could you try create a partial view or a partial view macro with this code, and place it on your template where you want to output the data.
To see if this works for you.
Hope this helps,
/Dennis
Well, the proof is in the pudding -- it is "possible to add Razor directly into the templates." I'm doing it locally. The *.cshtml macros only don't work on this server. I suspect I'll get the same error if using a partial view but I will try it later! Thanks again for staying with me on this! Cheers.
//Garrett
is working on a reply...