Join Mike Benkovich for an in-depth discussion in this video Adding a model, part of ASP.NET MVC 5 Essential Training.
- [Tutor] In this next section, we're going to add data to our application. And we're going to do that by taking advantage of the model, the model concept of MVC. What that is, it's just a simple class that we can add to our models folder. And that we can then use to help us structure the information that we're working with. So I'm going to add a model to support the idea of the different shows that we're going to be putting on. I'm going to call this my concert model. So I'm going to add a new class.
In this class I'm going to call Concert and my Concert class is going to be pretty straightforward. I'm going to have a number of different properties. Now I'm going to use a code snippet to be able to add them pretty quickly. And that's where you type in the characters prop. and Visual Studio identifies this as a code snippet. If you press the Tab key twice, it'll add that snippet and then it's an easy way to add your properties. So I'm going to add the string, a type for this, first property is going to be a name.
I'm going to have another property for the city where the concert is at. And we have another property for the concert date. And this will be a DateTime. And I'm going to have a couple of other properties one is going to be the number of tickets that we've got for the backstage. And we will say tickets available for backstage and then I've got a price for the tickets.
I will use a double for the price. Now that I've got my model, what I'm going to do is I want to add a controller to work with this and see how we can render out the different views and use that model throughout our application. So I'm going to create a controller here. Go and say add new controller. I'm just going to do an empty MVC 5 Controller we're going to call it concert controller. And this will allow us to go out and view information about a concert and by default will need to go out and display the concert that we're going to work with.
So here I've got my action result for the index, the default view for this concert and I'm going to create a new view and then we can edit it.
- Creating a new ASP.NET MVC 5 project
- Building custom routes
- Creating custom layouts
- Adding a model to a view
- Deploying to Azure and Amazon Web Services
- Configuring authentication and authorization
- Unit testing code