A decade ago, Microsoft Access provided a convenient and easy-to-learn project platform for people with little or no formal programming experience. It was ubiquitous, it was powerful, and there was lots of demand for it. Gradually, that’s changing. More and more, people need a way to interface with their custom programs from the web and/or from smart devices and tablets. The best answer is Microsoft MVC 5.
MVC stands for Model-View-Controller and the pattern has been around since the 1970s. The Microsoft implementation of MVC is part of ASP.Net and the current release, as of this writing, is version 5. Although it’s actually part of ASP.Net, it is distinct from ASP.Net Forms and may be used independently from Forms or in conjunction with them. ASP.Net Forms developers might disagree, but I found Forms to be heavy and clumsy. What makes an MVC application appealing to developers accustomed with Microsoft Access is the way Visual Studio obfuscates the complexity. It’s quick and easy to build an MVC application.
The 10,000 Foot View for Access Developers
Many Microsoft Access developers recoil at the thought of learning ASP.Net. It is an elephant, in more than one respect. New development environment, new code language, new GUI, and a new way of deploying solutions. It’s an enormous learning curve.
Figure 1: Going from table data to a form
Developing an application with MVC, on the other hand, might be likened to what one does in Access:
- Design a table.
- Invoke a Form Wizard.
- Beautify your form.
As is the case with Microsoft Access, MVC allows you to build without worrying about the SQL commands necessary to add, edit, and delete records. The table data, be that a single record, an empty record, or a list of records, is passed around as an object that knows how to do stuff. Once you explain to MVC what a data object looks like, it only requires simple commands, like these C# examples generated by the MVC scaffolding wizard for the MVC Movies tutorial:
Figure 2: The movie index
What’s more, the scaffolding engine that builds these VIEWS includes all the “command buttons” you need, in the form of HTML hyperlinks, as shown in the screen shot of the MVC Movie Index page (refer to Figure 2). It may look a little clumsy, but that’s what the wizard generates. As with Microsoft Access, it’s up to the developer to beautify it. But the functionality is there, right out of the box.
Zooming in on Model, Controller, and View
Although it’s not the purpose of this article to dive deeply into the code, it is necessary to understand the MVC concept. MVC relies on the Model-View-Controller pattern and well-defined conventions to simplify development. How is this to be understood by someone versed only in Microsoft Access?
Model: The model is like a Table in Access, but it’s so much more. In fact, one can begin building an MVC application without a data store of any kind. One only needs to describe what the data model looks like. The MVC Movie tutorial begins by creating a Movie Class that describes what we think of as fields in a table. It’s in this class where one adds validation rules (as can be done in Access tables) and foreign key relationships. By convention, all models are put in a folder named, not surprisingly, Models.
Controller: Think of the Controller piece as the VBA code window. The Controller handles requests, not unlike the Event Procedure paradigm, except in reality, it’s completely different. MVC uses web pages, which are stateless or disconnected. There is no “button-click event” in MVC, but there are actions. The Controller handles all the actions of your application.
View: Views in MVC are the equivalent of Forms in Microsoft Access and they are web pages. But, unlike traditional ASP.Net Forms, these are not as much actual ASPX pages as they are templates. The controller will do something, like retrieve a list of Movies, and merge that with the Index View to produce the page we showed earlier.
Now, what’s going to be a radical change for Microsoft Access developers is that the development environment is not WYSIWYG. You won’t be dragging, dropping, and resizing controls, at least not the way you’re used to. In an HTML View, controls are described with HTML tags or with special helper functions that generate HTML tags, as shown in Figure 3.
Figure 3: Viewing the HTML version of the controls
Before you start to feel overwhelmed, keep in mind that everything shown in these screen shots was created by the scaffolding wizard. (MVC does not call it a wizard, but that is what an Access developer would consider it to be.) This greatly simplifies the learning process, but understanding what Visual Studio has built for you will take a bit of dedication and time.
The first thing you need to do is to get a copy of Visual Studio, preferably 2013 or later. This needn’t cost you anything as you can download Visual Studio Express 2013 for free from the Microsoft site. If you don’t have access to a SQL Server, you may also want to download SQL Express 2012, which is also free.
Once you’ve installed the tools, you should visit the Microsoft MVC Page. There, you’ll find all the resources you need to start learning MVC. In addition to suggestions for books and some great free videos, there are a couple of tutorials that will really help you understand how it all works:
The good news for Access developers is that MVC is a comfortable stepping stone into ASP.Net. The bad news is that there’s still a lot of technology you need to learn. This includes:
- Visual Studio 2013
I bet you thought you could leverage your VBA skills to learn VB.Net? You probably could, but honestly, you’d be better off if you just decide to learn C#. The recommended tutorials use C# as the code language and, in general, C# is used by more development teams. Just bite the bullet and learn it.
LINQ (Language Integrated Query) is an exciting query language used in MVC and elsewhere. Because the MVC tutorial examples give little explanation, you might want to download a free tool called LinqPad. It’s a utility for writing and executing LINQ scripts and comes with lots of samples and tutorial examples.
Learning Visual Studio 2013
If you’ve never used Visual Studio, this could be a little intimidating. But, at least it’s free, provided you download the Visual Studio Express 2013 version. Once you work your way through a couple tutorials, you’ll no doubt feel comfortable. However, what really helps with learning to be efficient with Visual Studio is to watch as many videos as you can find. That’s where you’ll learn time saving shortcuts, tips, and tricks.
A lot of ideas have been introduced without diving deep into the code. Future articles will explore the following topics with the Microsoft Access developer’s point of view in mind:
- Where’s the Data: Code First EF in MVC 5
- MVC Scaffolding for Access Wizard Lovers