Creating a Movie Model and Controller in MVC

In this video, the author explains how to create a movie model and controller from scratch in an MVC application. First, they demonstrate how to add a new class using the right-click models feature in the Solution Explorer. They give the class a couple of properties, such as an ID and name, using the 'prop' code snippet.

The movie class is a plain old CLR object (POCO) that represents the state and behavior of the application in terms of its problem domain. It does not have any behavior or logic, only properties that represent state.

Next, the author shows how to create a 'movies' controller with a 'random' action by right-clicking on the controllers in the Solution Explorer. They opt to create the controller from scratch rather than using a template.

The movies controller is a simple class that derives from the controller class. The author renames the default 'index' action to 'random' since it will be called when the user goes to '/movies/random'. In the 'random' action, an instance of the movie model is created with the name 'Shrek'.

At this point, the author explains that the view for the 'random' action does not exist and needs to be added. They right-click on the 'views' folder in the Solution Explorer, create a new 'random' view, and select the 'underline layout' as the layout for all views in the application.

In the view, the author changes the heading to display the name of the movie by using the 'model' property that gives access to the movie model passed from the controller. They also specify the type of the model using a directive at the top of the file.

Finally, the author runs the application to see the result of their work. They open the browser and navigate to '/movies/random'. The view displays the name of the movie, confirming that the model, view, and controller are working correctly. The author concludes the video by mentioning that more sophisticated scenarios will be covered in the rest of the course.

video txt

Browse more

Exercise Summary

Exercise Summary

Using Bootstrap Dialog Box

Using Bootstrap Dialog Box

ASP.NET Web Project Working Method and Monitoring

ASP.NET Web Project Working Method and Monitoring

Summary of ASP.NET Core Razor Pages Training

Summary of ASP.NET Core Razor Pages Training

ASP.NET Web Form Controls - 2

ASP.NET Web Form Controls - 2

Using Predicate Builder for Filtering Data in .NET Core

Using Predicate Builder for Filtering Data in .NET Core

Using ASP.Net Core Identity to Add a User

Using ASP.Net Core Identity to Add a User

Debugging and Publishing an ASP.NET MVC Application

Debugging and Publishing an ASP.NET MVC Application

Creating a Login Form

Creating a Login Form

ASP.NET Status Management

ASP.NET Status Management

Implementing Pagination in ASP.NET Web API with Entity Framework Code

Implementing Pagination in ASP.NET Web API with Entity Framework Code

ASP.NET Web Page Optimization-Search Engine Optimization

ASP.NET Web Page Optimization-Search Engine Optimization

Creating ASP.NET Web Forms using Visual Studio 2022

Creating ASP.NET Web Forms using Visual Studio 2022

What is MVC?

What is MVC?

Program File Configuration and Interpretation in ASP.NET Core

Program File Configuration and Interpretation in ASP.NET Core

ASP.NET Web Form Controls-3 (Creating Web Pages Structure)

ASP.NET Web Form Controls-3 (Creating Web Pages Structure)

Adding Pagination, Sorting, and Filtering to Customers Table

Adding Pagination, Sorting, and Filtering to Customers Table

Using a Pure View Model for Form Initialization

Using a Pure View Model for Form Initialization

ASP.NET Web Form Controls

ASP.NET Web Form Controls

Handling Entity Framework Validation Errors

Handling Entity Framework Validation Errors

Implementing Features in the Vidli App

Implementing Features in the Vidli App

ASP.NET Data Management and Data Link Controls-2

ASP.NET Data Management and Data Link Controls-2

Adding a Delete Link for Each Customer

Adding a Delete Link for Each Customer

How to Solve Microsoft SQL Exception Invalid Column Name

How to Solve Microsoft SQL Exception Invalid Column Name

Optimizing click event handling for buttons

Optimizing click event handling for buttons

Summary of 'Login' Functionality

Summary of 'Login' Functionality

Partial Views in ASP.NET MVC

Partial Views in ASP.NET MVC

Introduction to ASP.NET MVC

Introduction to ASP.NET MVC

Adding Validation to Movie Form

Adding Validation to Movie Form

Building APIs with ASP.NET Web API

Building APIs with ASP.NET Web API

Two workflows to use Entity Framework

Two workflows to use Entity Framework

Summary of Text

Summary of Text

Summary of the text

Summary of the text

Using AutoMapper for Object Mapping

Using AutoMapper for Object Mapping

Creating a Movie Model and Controller in MVC

Creating a Movie Model and Controller in MVC

Welcome to the Ultimate Guide to ASP.NET Core

Welcome to the Ultimate Guide to ASP.NET Core

Preparing the Development Environment

Preparing the Development Environment

Summary of Text

Summary of Text

Migrating a Visual Studio Solution to ASP.NET 8

Migrating a Visual Studio Solution to ASP.NET 8

ASP.NET Data Management and Data Link Controls-1

ASP.NET Data Management and Data Link Controls-1

GitHub Repository for Whitley mvc-5

GitHub Repository for Whitley mvc-5

Summary of Student Management System Tutorial

Summary of Student Management System Tutorial

Populating Movies and Genres

Populating Movies and Genres