C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
ASP.NET MVC ModelA model is a class that contains the business logic of the application. It also used for accessing data from the database. The model class does not handle directly input from the browser. It does not contain any HTML code as well. Models are also refers as objects that are used to implement conceptual logic for the application. A controller interacts with the model, access the data, perform the logic and pass that data to the view. Creating a ModelLet's add a new model in exiting project. Model contains setter and getter for its properties. To add the model, just right click on the Model folder of the project and then follow this sequence Model->Add->New Item->Visual C#->Code->Class. It contains some default code as given below. // ClassicalMusic.csusing System; using System.Collections.Generic; using System.Linq; using System.Web; namespace MvcApplicationDemo.Models { public class ClassicalMusic { } } Now, we can add any number of properties and methods in the model. These are helpful to make MVC a clean framework approach. As here, we are creating some properties and a method. // ClassicalMusic.csusing System; using System.Collections.Generic; using System.Linq; using System.Web; namespace MvcApplicationDemo.Models { public class ClassicalMusic { public int ID { get; set; } public string Title { get; set; } public DateTime ReleaseDate { get; set; } public string Genre { get; set; } public string GetDateTime() { return DateTime.Now.ToString(); } } }
Next TopicASP.NET MVC Model Binding
|