My first website was simple with MVC pattern in ASP .Net Framework!

Tram Ho

I. What is ASP .NET and MVC pattern?

ASP.NET MVC is a web framework developed by Microsoft that implements the MVC (model – view – controller) model. ASP.NET MVC is an open source software, separated with proprietary components ASP.NET Web Forms. ASP.NET MVC is emerging as the most powerful and popular web development methodology on the current ASP.NET platform.

In later versions of ASP.NET , ASP.NET MVC, ASP.NET Web API, and ASP.NET Web Pages (platform that uses only Razor pages) will be merged into MVC 6.

  • Based on ASP.NET , ASP.NET MVC allows software developers to build web applications as a component of three roles: Model, View and Controller. The MVC model defines a web application with three logical layers:
  • Model (business layer – business layer)
  • View (display layer)
  • Controller (input control)

II. Create a basic ASP .NET application

1. Preparation

  • In order to practice well, you need to have basic knowledge of C #, using an IDE that supports ASP .NET and SQL Sever database management system, here I use Visual studio 2019 and SQL Sever 2014

2. Implementation steps

Step 1: Initialize the project Open visual studio and select create a new project => select the ASP .NET Web Application project (.NET Framework) “Pay close attention because it may be confused with ASP .NET core or ASP .NET but support for Visual basic language” Next we will configure information for the project Get a project and add a floder Context to get the folder structure as follows

Step 2: Initialize components and functions First, I will create a model – I will use the entity framework, so go to the project => Manage nuget package and install the following framework for me:

  • Create Product.cs in the models directory and configure the following:

  • Right-click on the controller folder and select add => Controller:
  • Reconfigured as follows to get 2 action Indexes – use to show lists and, details to display product details and create to add new products.

  • Next is to add a View to display for adding the product list, a form to add a new product and a product detail
  • Right-click on the ‘return view’ section in Action Index and select add view as follows
  • Right-click on the ‘return view’ section in Action Detail and select add view as follows
  • Right-click on the ‘return view’ section in Action Create and select add view as follows
  • Finally, go to App_start / RouteConfig.cs and edit the following

  • Run App or press F5 and get the following result And 2 functions are Edit and Delete you do the same offline 😅😅
  • Above I presented the process of getting acquainted with the mvc model in my ASP .NET Framework MVC, indeed I see compared to other programming languages, here we have to code very little, quite suitable for 1 lazy people like me 🤗🤗🤗
  • The first article should not avoid shortcomings, I hope you understand and leave comments for me to amend in the next article. 😇
Share the news now

Source : Viblo