Namespace reference in .NET MVC3 Razor view in VB?
How d开发者_JS百科o I reference a Namespace in .NET MVC3 with the Razor view engine?
I understand this can be done in C#:
@using Namespace;
However in VB this doesn't seem to work:
@Imports Namespace
(i'm talking about inside a .vbhtml file)
You're using the correct syntax for VB:
@Imports My.Full.Namespace
What I've found in a quick play around is:
- Sub namespaces of the MVC project will be picked up by intellisense once the
@Imports
statement is added - must be the complete namespace. - If you're referencing a namespace outside of the current MVC project then intellisense won't pick it up unless you do a rebuild.
@Jonathan is correct, it's the correct syntax and it needs the full namespace of your extension methods.
If your extension methods are still not recognised, you may need to insert this import before your own namespace:
@Imports System.Web.Mvc.HtmlHelper
When I added this intellisense offered my extension methods. I think it's something to do with having a reference to System.Web.WebPages, which also defines a HtmlHelper class. Perhaps that explains why migrating the code to a new project solved the problem.
Unfortunately, the intellisense problem with the Import statement still persists, it doesn't offer the namespaces up.
I realise this answer is somewhat late in coming, however this has held me up half of the day - hope it helps someone else avoid this pitfall.
精彩评论