@Damian, what error are you getting (assuming its more than just "Error loading Razor Script")? If it isn't more than "Error loading Razor Script" then try wrapping your script in a try/catch and write out the exception:
Also in the example you gave (@Html.Raw("<p>test</p>)), you are missing a double quote after the closing p tag, that would cause issues if that's how you have it in the code.
Ok ive dissected things and isolated the fault and it doesnt look like its Html.Raw. Should have done this yesterday but it was odd that everything was working untl i inserted the Html.Raw line.
I have now cut my razor macro right down to this and it works. Note the InitializePage() override that i am using but ive stripped out all code for the example.
The VERY SCARY part of this is I have sites running live that dont have this line in the override and they are working spot on!
Can someone elighten me as to what is it causing the issue because im worried about the other scripts ive got running but obviously dont want to mess with them as they have been working for months. Need to make sure they are ok its its not just a fluke they are running!
And Fuji - not sure why you have got that helper message as you have basically written a method that just wraps the Html.Raw so it basically just changes the name you are calling.
No need for it - you can just do @Html.Raw(string or string variable)
If i use just a variable from the page it works fine so it seems to be something that doesnt get setup for Html.Raw if the base class is not inititalized.
Cant access/use Html.Raw in macro
Going mad here and dont know whats heppened but umbraco doesnt recognise Html.Raw,
I get
Object reference not set to an instance of an object.
when i try something simple like @Html.Raw("<p>test</p>)
I think im doing something daft and cant see for looking at it.
Any ideas whats happened?
Hi Damian,
Am new to Razor was well, could you try doing something like
and call you message after
@message("test")
@Fuji, it doesn't work like that.
@Damian, what error are you getting (assuming its more than just "Error loading Razor Script")? If it isn't more than "Error loading Razor Script" then try wrapping your script in a try/catch and write out the exception:
Also in the example you gave (@Html.Raw("<p>test</p>)), you are missing a double quote after the closing p tag, that would cause issues if that's how you have it in the code.
Hi Douglas,
Yes true, am using it this way though,
//fuji
Hi,
Im not new to razor thats why its bugging me.
Missing the closing quote was a typo as i just typed it out.
The error im getting is in my first post:
Object reference not set to an instance of an object.
Also when i use visual studio @Html is not listed in the intellisense.
Ive used it tons of times before but its just vanished! Very odd.
Its like there is a namespace issue somewhere.
Ok ive dissected things and isolated the fault and it doesnt look like its Html.Raw. Should have done this yesterday but it was odd that everything was working untl i inserted the Html.Raw line.
I have now cut my razor macro right down to this and it works. Note the InitializePage() override that i am using but ive stripped out all code for the example.
As soon as i insert the Html.Raw it breaks:
@inherits umbraco.MacroEngines.DynamicNodeContext
<h1>Testing Raw</h1>
@Html.Raw("
However, it also works if i remove the InitializePage override so it looks like its that causing the issue.
I have used this override a lot previously so i know it works but something is not right!
Any ideas? Im now going to triple check this override.
Arghh! Everytime i edit the post it stuffs up the code ive inserted! Another forum bug. :(
Anyway the bottom code segment shown breaks but if i remove either the @Html.Raw or the overrride from the functions it works.
Cripes!
Looked at some examples and i was missing:
If i add that into the override it works.
The VERY SCARY part of this is I have sites running live that dont have this line in the override and they are working spot on!
Can someone elighten me as to what is it causing the issue because im worried about the other scripts ive got running but obviously dont want to mess with them as they have been working for months. Need to make sure they are ok its its not just a fluke they are running!
And Fuji - not sure why you have got that helper message as you have basically written a method that just wraps the Html.Raw so it basically just changes the name you are calling.
No need for it - you can just do @Html.Raw(string or string variable)
If i use just a variable from the page it works fine so it seems to be something that doesnt get setup for Html.Raw if the base class is not inititalized.
Had a hunt around the source code but because im unfamiliar with it I cant even find the correct class where the base page for a front end page is.
I'll leave this unsolved for a little bit to see if anyone can aid my understanding of whats going on here.
Thanks
Nobody?
I'll mark as solved but still would like to know whats happening here.
I just had the same issue and found this thread (your solution worked, btw), I'd be interested if anyone has an explanantion as well.
Yes its a weird one.
My guess is the HTML object gets initialised in the page initialisation event and if you override it it you must remember to call the base method.
Hence if you dont thats why you get the object reference not set error.
is working on a reply...