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 :-
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.
Install all the required packages from nuget package manager as shown in below image.
After installing the packages your solution explorer will be looks like as below image.
Now Right Click and Controller folder and Add a Employee Controller as shown in below image.
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;
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);
}
}
Now Right Click in View and add InsertData View as write the html code as like below image .
Now done the below changes in Program.cs file.
Now run the application you will get the output shown in below images.