How to Create First MVC .Net Core Application ?

In this tutorial I am going to demonstrate about basic application creation in MVC Core and we will learn how to create Controller ,Action Methods and Views. Also we will learn how to display Model data into View and Run the application using Program.CS file.

Steps to be followed here are :-

  • Create a ASP.Net MVC Core Web App Project.
  • Create A Employee Model Class and define the Properties in it.
  • Create a Controller named it Employee Controller.
  • Create one Action Method Named it InsertData inside the Employee Controller and write the business logic here and return the data into view.
  • Create a View for InsertData Action Method.
  • Register the URL pattern into the Program.cs file.
  • Run the Application and See the desired output.

To start with create a ASP.Net MVC core web app project using the web app template as shown in below image and name the project then select for some default options and target framework as like in below images.

Image is not available
Image is not available
Image is not available
Image is not available
Image is not available

Install all the required packages from nuget package manager as shown in below image.

Image is not available

After installing the packages your solution explorer will be looks like as below image.

Image is not available

Now Right Click and Controller folder and Add a Employee Controller as shown in below image.

Image is not available

Now Right Click on Model folder and add Employee Model class and add the below properties into it as shown in below code and image.

                    

 public int EmpId { get; set; }
 public string Name { get; set; }= string.Empty;
 public string Description { get; set; }= string.Empty;
 public string Address { get; set; }= string.Empty;
Image is not available

Now add one Action Method into Controller and name the Action method as "InsertData" and write the below code into it.

                    
 public class EmployeeController : Controller
    {
        public IActionResult InsertData()
        {
            Employee employee = new Employee();
            employee.EmpId = 1007;
            employee.Name = "Sudheer Singh Chouhan";
            employee.Address = "Bapat Square Indore";
            employee.Description = "Technical Project Manager";
            return View(employee);
        }
    }
Image is not available

Now Right Click in View and add InsertData View as write the html code as like below image .

Image is not available

Now done the below changes in Program.cs file.

Image is not available

Now run the application you will get the output shown in below images.

Image is not available