If this isn’t needed, the controllers could be a simple pass through to the view. Beyond the views you can also use the MVC controller, which can add processing power to speed things up or add an extra layer of security. You can still inject partial views, and the fluid flow of the Razor syntax is still there to use to your advantage. EditorTemplates and DisplayTemplates are still your friends, as are scaffolding templates. If you make calls back to the server to provide templates for your application, you can now use Razor to do the heavy lifting generating the HTML. I’ll highlight some examples with Angular and Knockout, but these techniques will work regardless of the framework you employ. With just a couple of tweaks, the generated markup is easily customized to fit the template expectations for whatever framework is used on the client. The Razor View Engine is a marvel when it comes to simplifying generation of HTML markup. In this article, I’ll focus on one of these features, the Razor View Engine. ASP.NET has a lot more to offer and its implementation of MVC provides many features that are still relevant, even when one of the client-side frameworks does much of the heavy lifting. This arrangement provides good separation of concerns, and many applications have been written following this pattern, but as a developer, you’re leaving a lot on the table. In this scenario, Web API controllers may often replace the processing that would have been handled by the MVC Controller in the past.Īs Figure 1 shows, there are minimal requirements for the Web Server and a full-fledged server for the Web API, and both servers need to be accessible from outside the firewall. The common approach is to build static HTML pages or fragments and serve them up to the client with minimal server-side processing.
How do you blend server-side MVC with client-side MVVM? For many, the answer is simple: They don’t blend. Having client-side frameworks implement the MVVM pattern and ASP.NET implement the MVC pattern on the server has led to some confusion. Anything we can do to ease the learning curve is a good thing. The result is a sharp learning curve that can frustrate developers trying to stay current as new frameworks go in and out of vogue. Each framework takes a different approach toward the design pattern, with a unique syntax for templates and introducing custom concepts like factories, modules and observables. But they all implement the design pattern differently, adding new features or solving recurring problems in their own ways. Some have proven to be helpful, others not so much. It can seem like there’s a new framework every week. That’s a lot to ask for from a Web app, but really this is only the starting point.Īs users started expecting more from Web applications, there was an explosion of client-side frameworks to “help” by providing a client-side implementation of the Model-View-ViewModel (MVVM) pattern. Beyond that, they need to be secure, visually engaging and do something useful. Users expect Web apps to be fast, engaging and work on every device from smartphones to the widest-screen desktops. Single-Page Application (SPA) apps are very popular and for good reason. Volume 33 Number 3 Use Razor to Generate HTML for Templates in a Single-Page App