Instead of passing around individual values one by one from controllers to views, you can use a model to store a set of data. The controller is responsible for updating the model, which can be associated with a view to get its data.
A model is just a class file with a .cs
file extension. In the Solution Explorer panel, you can add new model class files to the Models
folder. You may have noticed that there are choices available for MVC Controller
class and MVC View
page, but none for the Model
class.
To create a model class, we can select the Class option when adding a new item as follows:
In Solution Explorer, right-click the
Models
folder, and click Add | New Item.In the
Add New Item
dialog, select Class underCode
.Name the file
Human.cs
to create a new model.Verify that you have an empty class named
Human
.
Add the following fields to the Human
class:
public class Human { public int ID { get; set; } public string SocialSecurityNumber...