Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asp.Net MVC 3 Custom WebViewPage in different namespace breaks IntelliSense

I have custom class that extends WebViewPage that I use as the base for all my Razor views using the method outlined here: http://haacked.com/archive/2011/02/21/changing-base-type-of-a-razor-view.aspx. Everything works fine unless I move it to a namespace that's different from the namespace of the views themselves whereupon the IntelliSense stops working (yes, I included the namespace of the custom WebViewPage in the namespaces section in the system.web.webPages.razor section of the web.config in the views folder). Is there a way around this?

What I want to do eventually is move all the views into another project that the graphic designers have access to, but I don't want the custom WebViewPage class in that project. Is this possible without breaking IntelliSense?

like image 720
Brad Urani Avatar asked Mar 15 '11 19:03

Brad Urani


2 Answers

This is going to sound silly, but rebuild and restart Visual Studio a few times :-D

I just reproduced the issue, and tried everything to get it working (including changing pageBaseType in in addition to the one). I restarted VS, and it started working. Removed the part, and it still works after several clean/rebuild/restart cycles.

My Views/Web.config has this:

<system.web.webPages.razor>
    <pages pageBaseType="ClassLibrary1.MyBasePage">
</system.web.webPages.razor>

My web project has a reference to the ClassLibrary1 project.

My custom class (in ClassLibrary1) looks like this:

namespace ClassLibrary1
{
    public abstract class MyBasePage<T> : WebViewPage<T>
    {
        public string DannyName { get; set; }

        public MyBasePage()
        {
            this.DannyName = "Danny Tuppeny";
        }
    }
}

And when in the web projects Views/Home/Index.cshtml, I get intellisense for "@DannyName" when I type "@D".

Some things I tried that might have had an effect, but it's still working after I removed it:

  • Added the pageBaseType to the Views/web.config in the section
  • Added a non-generic version of the class:
    • public abstract class MyBasePage : MyBasePage { }
like image 136
Danny Tuppeny Avatar answered Nov 09 '22 12:11

Danny Tuppeny


I found out that it's enough to restart your Cassini / IIS Express / IIS web server.

like image 33
Jakub Konecki Avatar answered Nov 09 '22 12:11

Jakub Konecki