Skip to content
PotatoScript edited this page Feb 27, 2025 · 4 revisions

🏁 Basic Introduction to ASP.NET Core MVC

🎯 What is ASP.NET Core MVC?

ASP.NET Core MVC is a powerful framework for building web applications. It's part of ASP.NET Core, a modern, cross-platform web development framework that allows you to build websites, APIs, and services. The "MVC" in ASP.NET Core MVC stands for Model-View-Controller, which is a pattern used to organize your code in a clean and easy-to-understand way.

  • Model: Handles the data and business logic of your application.
  • View: Displays the user interface (UI) that users interact with.
  • Controller: Acts as the middleman, receiving input from the user, processing it, and returning the response via the View.

🖥️ Simple Diagram of MVC

Model Controller View
Handles Data Receives User Input Displays UI
Represents Business Logic Contains Action Methods Renders the HTML

🛠️ Key Features of ASP.NET Core MVC

  • Cross-Platform: ASP.NET Core works on Windows, macOS, and Linux.
  • Fast and Efficient: Optimized for performance, it can handle high-traffic websites.
  • Secure: ASP.NET Core comes with built-in security features to protect your website from attacks.
  • Flexible and Modular: You can choose the components you need and leave out the ones you don't.

🌟 What is ASP.NET MVC?

Before ASP.NET Core MVC, there was ASP.NET MVC. It's also a framework for building web applications, but it's specifically designed to run on the Windows platform. ASP.NET MVC uses the same MVC pattern, but it doesn't have some of the improvements and flexibility that ASP.NET Core MVC offers.

🖥️ Simple Diagram of ASP.NET MVC

Model Controller View
Handles Data Receives User Input Displays UI

⚙️ Key Differences Between ASP.NET MVC and ASP.NET Core MVC

To better understand how ASP.NET Core MVC is different from ASP.NET MVC, let’s break it down into several key differences:

1. Cross-Platform Support

  • ASP.NET MVC: Only runs on Windows.
  • ASP.NET Core MVC: Runs on Windows, macOS, and Linux. This makes it very flexible and perfect for cloud applications.

🌍 Example: Think of ASP.NET MVC like a Windows-only computer, while ASP.NET Core MVC is like a computer that works on any operating system, including macOS and Linux.

2. Performance

  • ASP.NET MVC: While fast, it is slower than ASP.NET Core MVC.
  • ASP.NET Core MVC: Designed for better performance. It’s lightweight and much faster due to optimizations in how it handles requests and processes them.

🚀 Example: ASP.NET Core MVC is like a sports car that can go faster, while ASP.NET MVC is like a regular car.

3. Modularity

  • ASP.NET MVC: More monolithic, meaning it bundles many features together.
  • ASP.NET Core MVC: Modular, meaning you only add what you need. This makes your application smaller and faster.

🧩 Example: ASP.NET MVC is like a big toy box with all kinds of toys, even ones you don’t need. ASP.NET Core MVC is like having separate toy boxes for each toy, and you only pick the ones you want to play with.

4. Dependency Injection

  • ASP.NET MVC: Does not come with built-in support for Dependency Injection (DI).
  • ASP.NET Core MVC: Has Dependency Injection built-in. DI helps you organize and manage your code better by automatically providing the objects you need in your classes.

🧰 Example: ASP.NET Core MVC is like a robot that can automatically pick up the right tool when it needs it, whereas ASP.NET MVC needs you to find the tool manually.

5. Unified Framework

  • ASP.NET MVC: Separates different types of applications, like web apps and APIs.
  • ASP.NET Core MVC: Combines ASP.NET MVC, ASP.NET Web API, and ASP.NET Web Pages into one unified framework.

🛠️ Example: ASP.NET Core MVC is like an all-in-one toolset for creating different types of applications, while ASP.NET MVC is like having separate toolsets for each task.

6. Hosting

  • ASP.NET MVC: Primarily hosted on IIS (Internet Information Services) on Windows.
  • ASP.NET Core MVC: Can be hosted on multiple platforms, such as IIS, Kestrel (built-in web server), and even cloud services like Azure.

🌐 Example: ASP.NET Core MVC is like being able to host your website on any server, while ASP.NET MVC is more like hosting it only on a Windows server.


💡 Advantages of ASP.NET Core MVC Over ASP.NET MVC

  • Cross-platform compatibility allows your application to run anywhere.
  • Better performance and speed, which makes it ideal for high-traffic websites.
  • Built-in Dependency Injection improves the structure and manageability of your code.
  • Unified framework makes it easier to create both web applications and APIs without worrying about separate technologies.

🔑 Summary

  • ASP.NET Core MVC is a modern, fast, and flexible framework that works across multiple platforms. It's designed to be easier to use and more efficient than the older ASP.NET MVC.
  • ASP.NET Core MVC combines the features of ASP.NET MVC and ASP.NET Web API into a unified framework.
  • With ASP.NET Core MVC, you can build everything from websites to APIs, and it's much faster and easier to manage than ASP.NET MVC.

🚀 Let’s Start Coding!

Now that you have a good understanding of ASP.NET Core MVC and its differences from ASP.NET MVC, we can dive into creating our first ASP.NET Core MVC application.


💡 Visual Guide and Icons

  • 🖥️ ASP.NET Core MVC: Cross-Platform | Runs on Windows, macOS, Linux
  • 🚀 Performance: Faster, optimized for high performance
  • 🧩 Modularity: Choose the components you need, make it lightweight
  • 🧰 Dependency Injection: Built-in automatic tool for managing code
  • 🛠️ Unified Framework: One toolset for multiple types of apps

home

1. History

  • Starting in 1997 (beginning of the Dot-Com Bubble) there was a huge push away from fat client desktop applications and a migration toward browser based web application.
  • ASP.NET was Microsoft's answer in 2002(end of Dot-com era) to Sun's maturing Enterprise Java Platform.
  • ASP.NET replaced the Classic ASP(Active Server Pages) technology. ASP -> ASP.NET
  • An ASP.NET page is web page that contains a mix of HTML markup and dynamic ASP markup
  • An ASP.NET is run on the server, combining the static HTML code, and updating the dynamic ASP elements to produce a final HTML page
  • An ASP.NET web page is also referred as Web Forms.
  • ASP.NET Core is Full Stack it run on Back End and Front End (Database, Business Logic, HTML)
  • ASP.NET Core can be combined with popular front-end services like angular, react, Vue and Mobile apps
  • It is a very flexible programming environment you can choose to work on separately on back end or front end or both together
  • Models Views and Controllers (MVC)
    Model classes (objects) manages the behavior and data
    View web page (Razor HTML); manages the display of data
    Controller connects models, business logic and web pages. handles page events and navigation between pages
    • The MVC design pattern helps to enforce separation of concerns to help you avoid mixing presentation logic, business logic, and data access logic together.
  • The overview of MVC [User] ------> [Router] router will look at the url send by user (www.site.com/orders?date=today) [Router]-----> [Controller] router send the information routes(name:"Orders", url:"{Orders}") to controller [Controller]-->[Model] controller will order to model to create a list of order Orders oList = Store.getOrders(today) [Model]------->[Database] Model will make request to the database to get the data SELECT + FROM orders WHERE date = 'today' [Database]---->[Model]--->[Controller] controller now will have a list of data from the datatabse Oders oList=Store.getOrders(today) [Conroller]--->[View] controller will show the list in the html of view Get View("showOrders.html", oList) and generate a list in html form
<h1>orders</h1>
<ul>
  <li>oList(1)</li>
  <li>oList(2)</li>
</ul>

home

2. Database Setup:

DATA ACCESS OBJECT (DAO) OBJECT RELATIONAL MAPPER(O)
・Manually crate tables ・Allow the computer to generate database table based on classes defined in the application
・Traditional method of database access ・Database is updated using migrations.
・Write your own SQL statements ・Entity Framework is Microsoft' ORM.
・Database managers(DBA's) usually prefer DAOs. ・Simple for basic applications.
・Provides more visibility on finding problems.

home

Clone this wiki locally