Blazor focuses on the .NET developers’ experience, translating C# logic which many Razor users are familiar with, into dynamic user experiences. If you choose to build your own, you can choose from a wide range of programming languages and frameworks. If you are a beginner, you will probably want to start with a framework and language that is easy to learn, well supported and robust. If you are considering making a career as a programmer, you probably want to know that the skills you acquire while learning your new framework will enhance your value to potential employers. In both cases, learning C# as a language and ASP.NET Core as a framework will tick those boxes.
ASP.NET Core MVC and the RazorViewEngine
When looking at an ASP.NET solution, Razor files will have extensions of .cshtml, .vbhtml, or .razor. The compiled artifact of Razor is executable code that writes HTML to the HTTP response. Razor Pages makes use of the popular C# programming language for server-side programming, and the easy-to-learn Razor templating syntax for embedding C# in HTML mark-up to generate content for browsers dynamically. Again, while Razor is reuseable by the OSS community, each framework’s particulars are tied to the inner-workings of ASP.NET Core. In short, OSS authors might need to rebuild elements to bring a similar API surface to developers. From our Blazor components, we can execute both client-side interactive code and make asynchronous server calls to run server-side dependencies.
The driving philosophy behind Razor is to bring ASP.NET developers closer into the web ecosystem by leveraging existing syntax and technologies. The traditional aspx format put ASP.NET developers at a disadvantage and made it difficult to leverage the HTML community’s advancements. The closer ASP.NET developers are to HTML, the more they can lean on other professionals, ecosystems, and technologies to deliver web-based solutions. Rather than be an opaque abstraction, Razor embraces HTML, CSS, and JavaScript as a necessity when building web applications.
- The driving philosophy behind Razor is to bring ASP.NET developers closer into the web ecosystem by leveraging existing syntax and technologies.
- Many MVC-style applications can be ported to Razor Pages with little modification to the views, apart from link generation, which now uses references to pages rather than controllers and actions.
- The MVC usage of Razor is likely the syntax and patterns developers will be most familiar with as it’s been around the .NET community the longest.
- All developers need to understand the view locating rules, which I’ve written about in a previous blog post, which I highly recommend reading.
Languages
We can see the @page directive again, similar to the usage under the Razor Pages programming model. The directive makes the Razor page accessible via a route, in this case, the current site’s root path. Also check out the .NET Homepage for released versions of .NET, getting started guides, and learning resources. Both core team members and external contributors send pull requests which go through the same review process. Some of the best ways to contribute are to try things out, file issues, join in design conversations,and make pull requests.
ASP.NET helpers are components that can be accessed by single lines of Razor code. The key difference between Razor Pages implementation of the MVC pattern and ASP.NET Core MVC is that Razor Pages uses the Page Controller pattern instead of the Front Controller pattern. Razor Pages razor developers is included within .NET Core from version 2.0 onwards, which is available as a free download as either an SDK (Software Development Kit) or a Runtime. The SDK includes the runtime and command line tools for creating .NET Core applications. The SDK is installed for you when you install Visual Studio 2017 Update 3 or later.
In general, code modifying HTML elements will run on the client, while code that accesses server dependencies will run on the server, with the results being marshaled back to the client via SignalR. Razor Pages is a great starting point for folks starting their ASP.NET journey, as it distills the required parts needed to build an interactive web experience. Adopters of Razor Pages will interact with concepts like rendering HTML, model binding, and request/response handling. As mentioned in the previous section, Razor’s intended use case was for the ASP.NET MVC framework, primarily powering the View parts that developers would be building. While ASP.NET MVC can support different view engines, the default is the RazorViewEngine found under the Microsoft.AspNetCore.Mvc.Razor namespace.
Razor Syntax
Components within the underlying MVC framework still have their uses such as using controllers for building RESTful APIs. You can still choose to use ASP.NET Core MVC to build your ASP.NET Core web applications. If you are porting an existing .NET Framework MVC application (MVC5 or earlier) to .NET Core, it may well be quicker or easier to keep with the MVC framework.
However, Razor Pages removes a lot of the unnecessary ceremony that comes with the ASP.NET implementation of MVC and is a simpler, and therefore more maintainable development experience. If you want a dynamic web site, that is one where the content is regularly being added to, you have a number of options available to you. You can use a Content Management System (CMS), of which there are many to choose from including WordPress, Umbraco, Joomla!