Web versions

Blazor MVC revives old technology for a modern and awesome web development framework – Visual Studio Magazine

New

Blazor MVC revives old technology for a modern and awesome web development framework

With ASP.NET MVC out of active development in favor of ASP.NET Core, a developer is reviving old MVC technology for the application in one of the hottest projects in the new open-source cross-platform “Core” world of Microsoft: Blazor.

Blazor, of course, is Microsoft’s new direction for C#-based web development, coming in two components for server-side and client-side. The latter is enabled by WebAssembly effectively acting as an assembly language-like compilation target for C# code so that it can be used in the browser instead of the usual heavy reliance on JavaScript.

As its name suggests, the Blazor MVC The project seeks to marry the old Model-View-Controller (MVC) architectural pattern with Blazor.

The idea is to provide a sort of on-ramp to Blazor for developers who are familiar with the old MVC model (from the 70s) and want to get into the new action of web development.

The components of this pattern to understand:

Model

The central element of the pattern. This is the application’s dynamic data structure, independent of the user interface. It directly manages the data, logic and rules of the application.

See
Any representation of information such as a graph, chart or table. Multiple views of the same information are possible, such as a bar chart for management and a table view for accountants.

Controller
Accepts input and converts it into commands for the model or view.

The MVC design pattern is used to separate concerns in an application, effectively decoupling user interface (view), data (model), and application logic (controller).

MVC pattern
[Click on image for larger view.] MVC pattern (source: Microsoft).

In it, website requests are routed to a controller responsible for working with the model to perform actions and/or retrieve data, Microsoft said. The controller chooses the view to display and provides it with the model. The view displays the final page, based on the model data.

The GitHub description of Blazor MVC reads: “Opt-in Model-View-Controller framework for Blazor. Keep UI logic out of layout and formatting. Enable decoupled screens and dynamically compound as well as broadcast UI events. From a founder of the ASP.NET MvcContrib library.”

This founder is Jeffrey Palermoa Microsoft MVP who is the chief architect of software architecture firm Clear Measure.

Today (July 26) he posted a YouTube video titled “What is Blazor MVC and why you should care“, in which he explains why he himself is so attached to this project.

He started caring about it soon after Microsoft released ASP.NET MVC in 2007.

“Microsoft created the first kind of concept of ASP.NET MVC when all web applications were sort of page-based applications and sprinkled with jQuery, a bit of JavaScript, before the industry moved to applications richer in the browser,” he said.

This prompted him to co-write a series of “ASP.NET MVC in Action” books. Then, and now, he was concerned about shoddy development practices.

“What I’ve seen with so many teams – and I’ve been working with development teams for so long that I see things happening over and over again – and one of the things that happens over and over again is that the UI of apps just becomes a big mess,” he said. “And there’s logic, there’s code to make things look right, and then there’s code for a screen to behave in a certain way, and when these two different types of code are in the same source file, it just creates a big mess.”

He was thrilled that Microsoft was making ASP.NET MVC a first-class template right out of the box with the File New Project templates in Visual Studio, which he saw as a way to avoid those confusing messes.

“I’ve cared about it ever since, and I’ve done tons of speeches about it,” he said. “But with Blazor sort of becoming the super popular new kind of app, this is once again relevant because the out-of-the-box model puts the control logic – or screen behavior – puts that kind of code in the same source file as code that makes the screen look a certain way.And you can use code behind it or whatever, but it ends up being in the same object that runs at runtime and it also makes a difference.

This is how he launched Blazor MVC, which comes in the form of a NuGet package which was last updated about eight months ago.

Blazor MVC
[Click on image for larger view.] Blazor MVC (source: NuGet).

The tool’s description says it helps developers add C# MVC functionality to any Blazor app. “Developers who have used this framework before can have a familiar structure and quickly transition to Blazor,” he continues, listing these features:

  • Compatibility with .NET 3, .NET 5 and .NET 6 [basically anything that supports .NET Standard 2.1]
  • Compatibility with Blazor Server and Blazor WebAssembly apps
  • Example projects on how to implement Blazor MVC
  • Create controllers and models for each of your views by extending prebuild classes

The v2.1.1 update has been downloaded around 1,200 times, while all versions have been downloaded around 3,400 times.

“Thanks for the video, I was looking for this topic,” reads a comment appended to the video from Palermo today.

About the Author


David Ramel is an editor and writer for Converge360.