Thursday, November 23, 2023

ASP.NET Core MVC

 Here are some common ASP.NET Core MVC interview questions and answers:

Q1. What is ASP.NET Core MVC?

A1. ASP.NET Core MVC is a web framework from Microsoft that implements the model-view-controller (MVC) pattern. It allows you to build web applications and APIs using .NET Core.

Q2. What are some key features of ASP.NET Core MVC?

A2. Key features include:

- Lightweight and high performance

- Built on .NET Core which runs on Windows, MacOS and Linux

- Integrated support for client-side frameworks like Angular, React and Bootstrap

- Flexible configuration and routing 

- Dependency injection

- Razor view engine to build UI using C# and HTML

Q3. What is the role of models, views and controllers in ASP.NET Core MVC?

A3. Models represent the application data and business logic. Views are responsible for the UI to interact with users. Controllers handle requests from clients, interact with models and pass data to views.

Q4. How is ASP.NET Core different from ASP.NET MVC?

A4. ASP.NET Core is a re-architected version of ASP.NET and runs on .NET Core. It is cross-platform, faster and more flexible. ASP.NET MVC runs on the traditional .NET Framework so it is Windows-only.

Q5. What is dependency injection in ASP.NET Core and why is it useful?  

A5. Dependency injection (DI) is a technique to achieve inversion of control between classes and their dependencies. In ASP.NET Core, you can use DI to configure services and inject them into controllers/other classes in your application startup. This makes your code loosely coupled.

Q6. How do you configure middleware in ASP.NET Core?

A6. Using IApplicationBuilder interface, which provides methods like Use(), Run() etc. to configure the HTTP pipeline with middleware components. The pipeline is configured in Startup.cs file in the Configure() method.

Q7. What is view models in ASP.NET Core MVC?

A7. View models are classes defined specifically to pass data from controllers to views. They only contain data needed for a view and help to maintain separation of concerns.

Q8. How do you manage client-side packages in ASP.NET Core?

A8. Using Node Services to execute Node.js command line interfaces to install packages like Bootstrap, jQuery etc. Bower can also be used to manage client-side libraries.