Posts

Showing posts from April, 2023

How to do Model Validation in Asp.net Core?

Image
Model Validation in .NET core: Model validation is an essential part of any web application that deals with user input. In ASP.NET Core, model validation can be performed by using built-in validation attributes and model binding. Here are the steps to perform model validation in ASP.NET Core: 1.Define validation attributes on model properties:  ASP.NET Core provides  System.ComponentModel.DataAnnotations namespace in which we get several built-in validation attributes that can be used to specify the validation rules for model properties.For example, the [Required] attribute can be used to specify that a property is required, while the [EmailAddress] attribute can be used to validate that a property contains a valid email address. 2.Enable model validation:  To enable model validation in ASP.NET Core, you need to add the [ApiController] attribute to your controller class and call the [FromBody] attribute on the input parameter of the action method. This will automatically ...

.NET Core Features

Image
 Here are 10 key features of .NET Core: Cross-platform support: .NET Core can be used to build applications that run on Windows, macOS, and Linux. High performance: .NET Core is designed to be fast and efficient, with features like just-in-time (JIT) compilation and asynchronous programming. Open-source licensing: .NET Core is available under the MIT license, making it free and open-source. Modular architecture: .NET Core's modular design allows developers to use only the components they need, reducing the size and complexity of applications. Dependency injection: .NET Core includes built-in support for dependency injection, making it easier to manage dependencies and improve code maintainability. Web development: ASP.NET Core, built on top of .NET Core, provides a powerful framework for building modern web applications. Entity Framework Core: .NET Core includes a lightweight version of Entity Framework for database access. Command-line interface (CLI): .NET Core includes a...

.Net core 3.1 Folder structure

Image
In .NET Core 3.1, the default folder structure for a new MVC web application project is as follows: you can see default folder structure in following image - /Controllers: This folder contains the controllers for the application. /Views: This folder contains the views (HTML templates) for the application. /Models : This folder contains the models for the application. /Data: This folder contains the data access layer for the application. /wwwroot: This folder contains the static files (e.g. images, JavaScript, CSS) for the application. /appsettings.json: This file contains the configuration settings for the application. Such as connection  strings, various app secrets /Program.cs : This file contains the entry point for the application i.e. Main method. /Startup.cs: This file contains the startup configuration for the application.it  contains two most important methods i.e. configureService method and configure method You can customize this folder structure to suit your ne...