Archive for the ‘MVC’ Category

ASP.NET MVC & VB – Where are the examples

July 3, 2012 3 comments

I finally got around to teaching myself ASP.NET MVC (using 4.0 / razor / Entity Framework 4.1 / VS 2012 RC) and found myself in a bit of a bind today. Despite the fact that I am a VB.NET MVP I have been working in C# just so I can keep my chops up with the language. I never get the chance at work to use C# so I force myself to do all personal projects in C#. The short of it is that I love MVC 4 and especially the razor syntax. Very powerful, very flexible. I have been catching on quickly enough and have found ample examples on the web to do what I need, which is very comforting to know that there is a huge amount of support for what is still not the mainstream web technology for MS (yet!).

And then I started up a test project at work to show some colleagues. It was in VB.

The experience could not have been more night and day. Examples of razor code segments in VB on the Googlewebs is like finding a needle in a haystack. To clarify, I was searching for specific answers — if I just did a general search like “MVC4 VB.NET” then I would find basic tutorials easy enough. But I’m not looking for encompassing tutorials. I’ve already started getting into the details of implementation so I need to solve specific issues. Unfortunately that sort of content appears to be blanketly in C# and I have to say that this is disheartening to a professed VB-enthusiast. For instance, I was trying to find the syntax for declaring a WebGrid HTML helper in razor (recall that I am new to MVC) so whatever I had used back a few weeks ago was half-fading from memory. Not a problem though – I’ll just find a quick sample from some forum thread or article just to get the ball rolling – a mix of search terms that included “MVC3”, “MVC4”, “VB.NET”, “webgrid” and “razor” I eventually had to give up around my twelfth result and translate a C# example instead. Honestly, I would have done this much earlier but I was just amazed at the lack of VB coverage. I pride myself on finding things fast through search – even with technologies I’ve never even seen before. This however was debasing. (For the record is a good reference that has ample dual language examples.)

So what’s with the near absence of VB code samples anywhere – in MS documentation or in developer forums. I can only conclude that ASP.NET MVC 3/4 is not a technology widely adopted by VB.NET developers. I know there are plenty of VB.NET developers out there but I suspect that the perception that VB’ers are mainly stuck on Windows client applications (Winforms mostly) may have some truth to it. Windows development does constitute about 90% of the content in the MSDN Visual Basic General forum forum. It’s what I have done primarily for the last seven years. The VB language team at Microsoft, through the effort of achieving “language parity”, has done a stellar job of elevating the language to the position of true equal to C# in terms of power and flexibility (with a very few exceptions) with the onset of .NET 4.5. Its detractors have little more than perception and job market opportunities to point to for C# superiority. Unfortunately for VB those things count for a lot. Too bad though. Vb.NET is a great language that, together with the power of the Visual Studio IDE, can offer blinding fast speed for the experienced developer as well as clear and simple readability. As evidence I offer case-insensitivity, auto-completion, code prettification and the lack of superfluous curly braces.

One last gripe with my brief exploration of MVC 4 with VB.NET. When trying to create an out of the box “basic” solution on my home machine (VS 2012 RC) I received the following error from the IDE at the tail end of generating the solution:

MVC 4 Error

I believe this may be behind my inability to access the WebGrid class in code on the razor form – thank goodness my real project is done in C#. I’ll have to assume this is some issue with VS 2012 RC (since the project I did at work was with VS 2010 SP1) but this whole business with VB has got me paranoid now. The second time I started a VB MVC 4 project at work using VS 2010 I noticed another issue. With VB defaults set to Option Strict On (which is recommended) some of the auto-generated code fails to compile because of loose casting. My guess is that the generation code was written for C# first and then ported to VB CodeDOM parser without a proper review of project context. This just suggests to me that VB was an afterthought. Kinda pisses me off, really.

Categories: MVC, Uncategorized, Visual Basic Tags: , ,