An Issue with Area in ASP.NET MVC 3 (VB.NET)


          ASP.NET MVC allows you to break/partition your large application into smaller parts. You can use Area in ASP.NET MVC (C# and VB.NET) projects easily. But I have found an issue regarding Area in ASP.NET MVC 3 Tools Update when working with a ASP.NET MVC 3 (VB.NET) project. Note that I am saying ASP.NET MVC 3 Tools Update and ASP.NET MVC 3 (VB.NET), because this issue is specific to both of them. You will not find this issue in ASP.NET MVC 2 (VB.NET), ASP.NET MVC 3 (C#), ASP.NET MVC 3 RTM(not Tools Update) (VB.NET), etc, project. In this article, I will show you the issue with Area and also show you a quick solution. 




          To see this issue in action, create an ASP.NET MVC 3 (VB.NET) project. Then, add an Area in this project. Next, add a controller inside this Area. Now run this application and navigate to this controller action. You will see the following screen,




          Something going wrong in this project. Now follow the same process as above but now with ASP.NET MVC 3 (C#). You will find that everything will work well ASP.NET MVC 3 (C#) project. Now compare your ASP.NET MVC 3 (C#) Area's controller namespace with ASP.NET MVC 3 (VB.NET),  


          ASP.NET MVC 3 (C#):




          ASP.NET MVC 3 (VB.NET):





          The above screens shows that ASP.NET MVC 3 (VB.NET) project adding wrong namespace in controller inside an Area. You may be thinking that why the controller's namespace(in above screen) is wrong in ASP.NET MVC 3 (VB.NET) and correct in ASP.NET MVC 3 (C#) project. The reason is that every route registered in an Area(in MyAreaAreaRegistration.cs file) have DataTokens["Namespaces"] equal to a string array with one string element which value equals to MyApplication.Areas.MyArea.*, which tell the Framework that look in the namespaces starts with ApplicationName.Areas.MyArea before looking anywhere else and DataTokens["UseNamespaceFallback"] equal to false, which tell the Framework that look only in the specified namespaces. Since the controller's namespace in ASP.NET MVC 3 (VB.NET) project is MyApplication, that's why it shows you the 'The resource cannot be found' screen. So the quick way to make your ASP.NET MVC 3 (VB.NET) project work, just replace MyApplication namespace with MyApplication.Areas.MyArea.Controllers namespace. Run again your ASP.NET MVC 3 (VB.NET) application, you will find that everything will work just fine.   


          Again note that this issue is only specific to ASP.NET MVC 3 (VB.NET) and  ASP.NET MVC 3 Tools Update.



          With Areas in ASP.NET MVC, you can easily break/partition your large application into smaller units. In this article, I showed you an issue regarding Area in ASP.NET MVC 3 (VB.NET) project. I also showed you a quick solution. Hopefully you will enjoy this article too. 


1 Comment

Comments have been disabled for this content.