Since there isn't 273 lines in this razor file I'm thinking it's some caching you're seeing. Is the razor macro cached?
I have copied your exact code into a razor macro and it's not throwing any errors. Try adding ?umbDebugShowTrace=true to your URL and scroll down to look for the red error to see what it says.
I'm using WebMatrix 2, the final version that was released a few days ago.
Sorry the error was when the full partial was being called, but the same error occurs (different line number) with just the above code which to me does't have any issues. When I uplaod it to my webserver, it runs perfectly fine (the full macro or the short code above).
I am calling it via @RenderPage()..... This started to occur with a webmatrix upgrade from last week.. The full error: http://screencast.com/t/US4b1Ulmzw
Does it work when you implement it as a macro instead of using inline razor code in the template (not saying it's the best solution, just trying to pinpoint the problem area).
Still a no go however I did fix it. I have no idea why it works but I made the following change (similar to both scripts that were failing, others weren't). Again this just started all of a sudden and it compiles/run fine on the server but not on my dev machine.
I was able to correct the problem by moving the inline razor to a .cshtml file and creating a macro. Once the macro was inserted and the inline razor removed the code worked as expectd.
Also lucuma in the razor code try removing the @ before the Model.AncestorOrSelf(level) as I it is already covered by the @{ before the variable declaration. This corrected my issue as well.
Good call, I can't recall if that was just a typo on my part after trying a million things. The wierd thing is that it all of a sudden stopped working locally but was fine on the server which I can't explain by that @..
Exact same thing with me. When you create a .cshtml script inside Umbraco and select on of the templates like navigation it will prepopulate the razor code for a generic navigation. The snippet contains the @Model error along with others like no space between the ul, li tags and html.raw helpers. So that is where in my code I had the @Model.
Yeah I have also been there by adding @ before Model and get an error.
If work withRazorin a Umbracoversion4.x. Umbraco version 4 forgives you, if you add an @ before Model in if statements, but in v6 are not forgiven.
So in razor in a v4 of Umbraco you can do this:
@if(@Model.Name=="home"){ <p>Thisis the homepage!</p> } @if(@Model.NodeTypeAlias=="TextPage"){ <p>thisis a textpage</p> }else{ <p>this ia NOT a textpage</p> }
And in a v6 you have to do it like this:
@if(Model.Name=="home"){ <p>Thisis the homepage!</p> } @if(Model.NodeTypeAlias=="TextPage"){ <p>thisis a textpage</p> }else{ <p>this ia NOT a textpage</p> }
In the first place you shouldn't have been allowed to write @ in the if statements before Model in version 4, but this is now enforced in Razor 2.0.
I hope this was a good explanation of why you sometimes can write @Model in if statements and foreach loops and so on.
Razor Errors - All of a sudden
I upgraded my webmatrix and now out of the blue I'm getting these errors on two razor scripts:
The strange thing is that if I remove all the contents of a script so it looks like the following, it still generates the same error. Any help here?
Since there isn't 273 lines in this razor file I'm thinking it's some caching you're seeing. Is the razor macro cached?
I have copied your exact code into a razor macro and it's not throwing any errors. Try adding ?umbDebugShowTrace=true to your URL and scroll down to look for the red error to see what it says.
I'm using WebMatrix 2, the final version that was released a few days ago.
Sorry the error was when the full partial was being called, but the same error occurs (different line number) with just the above code which to me does't have any issues. When I uplaod it to my webserver, it runs perfectly fine (the full macro or the short code above).
I am calling it via @RenderPage()..... This started to occur with a webmatrix upgrade from last week.. The full error: http://screencast.com/t/US4b1Ulmzw
This is how it is called:
Does it work when you implement it as a macro instead of using inline razor code in the template (not saying it's the best solution, just trying to pinpoint the problem area).
Still a no go however I did fix it. I have no idea why it works but I made the following change (similar to both scripts that were failing, others weren't). Again this just started all of a sudden and it compiles/run fine on the server but not on my dev machine.
I'm having the same issues after upgrading webmatrix. No changes were made. Errors below:
rror Loading Razor Script (file: ) c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fba73c04\9cd6049e\App_Web_inline-e7ec17aa061628d3bfac4b57f36964d6.cshtml.ae9e2569.isnvsjcc.0.cs(60): error CS1513: } expected at System.Web.Compilation.AssemblyBuilder.Compile()
at System.Web.Compilation.BuildProvidersCompiler.PerformBuild()
at System.Web.Compilation.BuildManager.CompileWebFile(VirtualPath virtualPath)
at System.Web.Compilation.BuildManager.GetVPathBuildResultInternal(VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetVPathBuildResultWithNoAssert(HttpContext context, VirtualPath virtualPath, Boolean noBuild, Boolean allowCrossApp, Boolean allowBuildInPrecompile, Boolean throwIfNotFound, Boolean ensureIsUpToDate)
at System.Web.Compilation.BuildManager.GetVirtualPathObjectFactory(VirtualPath virtualPath, HttpContext context, Boolean allowCrossApp, Boolean throwIfNotFound)
at System.Web.Compilation.BuildManager.CreateInstanceFromVirtualPath(VirtualPath virtualPath, Type requiredBaseType, HttpContext context, Boolean allowCrossApp)
at System.Web.WebPages.BuildManagerWrapper.CreateInstanceOfType[T](String virtualPath)
at System.Web.WebPages.VirtualPathFactoryExtensions.CreateInstance[T](IVirtualPathFactory factory, String virtualPath)
at System.Web.WebPages.VirtualPathFactoryManager.CreateInstanceOfType[T](String virtualPath)
at System.Web.WebPages.VirtualPathFactoryExtensions.CreateInstance[T](IVirtualPathFactory factory, String virtualPath)
at System.Web.WebPages.WebPageBase.CreateInstanceFromVirtualPath(String virtualPath, IVirtualPathFactory virtualPathFactory)
at umbraco.MacroEngines.RazorMacroEngine.CompileAndInstantiate(String virtualPath)
at umbraco.MacroEngines.RazorMacroEngine.ExecuteRazor(MacroModel macro, INode currentPage)
at umbraco.MacroEngines.RazorMacroEngine.Execute(MacroModel macro, INode currentPage)
Error loading MacroEngine script (file: , Type: ''
c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\fba73c04\9cd6049e\App_Web_inline-09cbddcbf5c3f65e327d878d0bb90b48.cshtml.ae9e2569.fqzrrsfn.0.cs(61): error CS1513: } expected
at umbraco.macro.renderMacro(Hashtable pageElements, Int32 pageId)
I was able to correct the problem by moving the inline razor to a .cshtml file and creating a macro. Once the macro was inserted and the inline razor removed the code worked as expectd.
Also lucuma in the razor code try removing the @ before the Model.AncestorOrSelf(level) as I it is already covered by the @{ before the variable declaration. This corrected my issue as well.
Good call, I can't recall if that was just a typo on my part after trying a million things. The wierd thing is that it all of a sudden stopped working locally but was fine on the server which I can't explain by that @..
Exact same thing with me. When you create a .cshtml script inside Umbraco and select on of the templates like navigation it will prepopulate the razor code for a generic navigation. The snippet contains the @Model error along with others like no space between the ul, li tags and html.raw helpers. So that is where in my code I had the @Model.
Thanks Jason. Been pulling my hair out and it turned out to be the erroneous @ before Model. Sometimes it's the little things.
Hi Andy,
Yeah I have also been there by adding @ before Model and get an error.
If work with Razor in a Umbraco version 4.x. Umbraco version 4 forgives you, if you add an @ before Model in if statements, but in v6 are not forgiven.
So in razor in a v4 of Umbraco you can do this:
And in a v6 you have to do it like this:
In the first place you shouldn't have been allowed to write @ in the if statements before Model in version 4, but this is now enforced in Razor 2.0.
I hope this was a good explanation of why you sometimes can write @Model in if statements and foreach loops and so on.
/Dennis
is working on a reply...