How to get Razor intellisense for @model in a class library project

How to get Razor intellisense for @model in a class library project

Rate This
  • Comments 2

Many of us follow a modular architecture and create MVC3 Razor view in a separate class library project.

Following  is a screenshot of the class library project that I have created.

Now if I open a view with @model typed in it, I notice  that it shows squiggle for @model and no intellisense is shown. (error: There is build provider registered for the extension '.cshtml')

The reason behind the error is that Visual Studio 2010 (for Razor tooling) requires web.config file (with some specific settings)  to be in the project so that the MVC Razor host (which adds the @model directive) gets registered correctly. 

The workaround would be  to drop the attached web.config (rename the attached file from web.txt to web.config)  to the root of the project. Close,  reopen the file and Boom, intellisense is back for @model inside the class library project.

 

 

 

Hope this helps,

Deepak

Attachment: web.txt
Leave a Comment
  • Please add 3 and 7 and type the answer here:
  • Post
  • How do you use these views within host application ?

    I've recently found this solution: www.chrisvandesteeg.nl/.../embedding-pre-compiled-razor-views-in-your-dll and after reading this post I feel that I miss something here?

    Or maybe you just xcopy your views to the hosting app Views directory using AfterBuild event - or similar thing?

  • Thank you I've been looking into this all day.

Page 1 of 1 (2 items)