This project is read-only.

Strongly typed view

Feb 6, 2011 at 7:13 PM
Edited Feb 6, 2011 at 7:15 PM


I am learning your cms and trying to figure out how everything works. I am a student and try to be teached by your cms.

You made a great job. I admire your cms. And now i have problem with understanding of strongly typed views in modules.

How did you make them working? As i understand you add to event CodeGenerationStarted your function. And it adds assamblies provider.AssemblyBuilder.AddAssemblyReference(assembly);

As I've read a lot about this i thought it is only place what makes strongly types working. But when i tried to make the same thing in new mvc application i have error that the view is nt found but it is there.

So please can yu explain how did you do that working and if there others ways? Or if you have no time to explain me this maybe you can print the names of files in orchard where i could look and i will try to learn out by myself.

Sorry for my bad english i am learning it too:) Maybe in future i can help developing this cms.


Feb 6, 2011 at 8:28 PM

CodeGenerationStarted is pretty much all there is to it. Note that this works only for Razor (.cshtml) views. WebForms (.ascx) views work differently.

When compiling a chtml view, the razor view engine build provider adds the following assembly references:

  • Assemblies in "~/bin"
  • Assemblies specified in "web.config" files (from the folder where the view is located up to the root web.config)
  • (Orchard specific:) Assemblies added by the "CodeGenerationStarted" event handler

If you are trying to make this work in a "stand alone" application. make sure to look at the root web.config file of Orchard.Web. There are a few things that need to be specified there for things to hook up properly.



Feb 7, 2011 at 7:05 AM


Thanks for relply Renaud. But i am still confused. SO i have view engine that specifies certain path to views. And I added code to CodeGenerationStarted event.

You said: "When compiling a chtml view, the razor view engine build provider adds the following assembly references". But it doesn't work with it. The error in :

the view is not found and it shows where it was looking and there is right view. Why it didn't fin it? Maybe i need something special or to ovveride some other class.Maybe WebViewPage??

I looked to web.config of Orchard.Web and didn't see anything special.

Maybe this row : <probing privatePath="App_Data/Dependencies"/>. In CodeGenerationStarted  event i see that you add

foreach (var virtualDependency in entry.dependencies) {  provider.AddVirtualPathDependency(virtualDependency); }

Is it important? Because when i commented it in Orchard the cms still working:)

THanks for help,