Archive for August, 2010

Gotchas: ASP.Net MVC 3 Release 1 – Razor – Import directives

Just a reminder that when using Razor (at least the version released with MVC 3 Release 1) isn’t the WebFroms view engine… I know this might be obvious but the things that you might overlook are things that we take for granted like the Import Directives in the web.config…

As far as I am aware these plus other options/settings are tied in with the standard ASP.Net view engine and aren’t known by Razor (at least at this point).

I learn’t this the hard way when trying to use Import Directives to save having to put using statements in my pages for the HTML Extensions that I’ve created… I was getting the following exception without knowing why (the lack VS support in Release 1 hurts a bit):

CS1061: ‘System.Web.Mvc.HtmlHelper<object>’ does not contain a definition for ‘ScriptCss’ and no extension method ‘ScriptCss’ accepting a first argument of type ‘System.Web.Mvc.HtmlHelper<object>’ could be found (are you missing a using directive or an assembly reference?)

It turns out that because Razor isn’t the standard view engine its not going to be looks for the Import Directives the same why the old view engine does.

Hope that helps.