Blazor - Overview

C# ASP.NET offers a way to build highly interactive web UIs using C# and .NET. Blazor helps us to make the app interactive via different modes such as Static Web Apps Interactive Server ( Blazor Server ) WASM (Web Assembly) A Blazor app is based on Components with .razor extention. It is a combination of C# and HTML. Example: // Counter.razor @page "/counter" @rendermode InterativeServer <PageTitle>Counter</PageTitle> <h1>Counter</h1> <p role="status">Current count: @currentCount</p> <button class="btn btn-primary" @onclick="IncrementCount">Click me</button> @code { private int currentCount = 0; private void IncrementCount() { currentCount++; } } // PageTitle.razor <h3>@ChildContent</h3> @code { [Parameter] public RenderFragment ChildContent { get; set; } } In the above example, <PageTitle> is another component. @code block is used to write the C# code. This block will render a counter and a button to increment the counter. ...

Razor Pages - Overview

Razor pages provides a way to build web applications using a page-focused approach. Under the hood, it uses the same routing and middleware as MVC, and it provides directory-based conventions for views. Pages can have a viewmodel where we can define page data and actions. Pages: Pages are the main part of a Razor Pages application. Pages are created in the Pages directory and are named with the .cshtml extension. Each page can have a corresponding .cshtml.cs file which contains the page model. Page Model: The page model is responsible for handling requests and rendering the page. It is a class that contains the data and actions for the page. The page model is defined in a .cshtml.cs file and is associated with a .cshtml file. Getting Started Create a new project using the dotnet command-line interface. ...

Dotnet MVC - Overview

C# asp.net MVC is a web application framework that provides a model-view-controller architecture. The MVC pattern separates the application into three main components: the model, the view, and the controller. This separation of concerns makes it easier to manage and maintain the application. This structure also makes it easier to test and debug the application. Model: The model represents the data and core business logic related to data of the application. It is responsible for managing the data and the rules for accessing and updating the data. The model is independent of the user interface and can be reused across different views. View: The view is responsible for presenting the data to the user, think of HTML Templates. It is the UI of the application and is responsible for rendering the data to the user. The view is independent of the model and the controller and can be reused across different models and controllers. Controller: The controller is primarily responsible for handling user input and requests. It processes the input, interacts with the model, and selects the view to be rendered. The controller is responsible for the flow of the application and is the glue between the model and the view. Underneath, it uses kestrel server to host the application and uses asp.net core for web development. ...

C# - Testing

C#, NUnit has a lot of features that makes it a good choice for testing. It provides features for writing and running tests, and also for creating test fixtures and test suites. NUnit is a popular choice for unit testing in C# due to its simplicity and extensibility. Writing Tests NUnit provides a set of attributes that can be used to write tests. The Test attribute is used to mark a method as a test method. The TestCase attribute is used to provide test data for parameterized tests. The SetUp and TearDown attributes are used to mark methods that should be run before and after each test method, respectively. ...

C# - Overview

C# (pronounced “C Sharp”) is a modern, object-oriented, and type-safe programming language developed by Microsoft. It is widely used for developing desktop applications, web services, and mobile apps. C# supports multiple programming paradigms, including imperative, declarative, functional, generic, object-oriented, and component-oriented programming. Few things I like about C# are It’s a simple and easy to learn language. The extensive standard library and ecosystem, including ASP.NET and .NET Core. Few things I dislike about C# are ...