ASP Module 2
Getting Started with MVC
Getting Started with MVC
  • Overview
    • Introduction to MVC
  • Understanding MVC
    • Creating an MVC app
    • Add a controller
      • Understand HTTP endpoint
      • Understand basic routing
    • Add a view
      • Understanding shared layouts
      • Setting view title
      • Passing data to view
  • Exercise
    • Add two numbers
      • Using Model
  • Display Movies
    • Add a model
      • Scaffold the index view
      • Scaffold the movies controller
      • Add temp movie data
      • Pass data to index view
    • Implement actions
      • The first create action
      • The second create action
      • The details action method
      • Edit & Delete actions
      • Asynchronous actions
    • Repo link
Powered by GitBook
On this page
  • Let us scaffold the movies controller
  • This was the MoviesController generated
  1. Display Movies
  2. Add a model

Scaffold the movies controller

PreviousScaffold the index viewNextAdd temp movie data

Last updated 2 years ago

Let us scaffold the movies controller

Follow the steps to generate the code for the Movies Controller.

Start by right clicking the controller and:

Click on Add

This was the MoviesController generated

We can do this manually as well, but to save time we can always generate such boiler plate code!

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace MvcMovie.Controllers
{
    public class MoviesController : Controller
    {
        // GET: MoviesController
        public ActionResult Index()
        {
            return View();
        }

        // GET: MoviesController/Details/5
        public ActionResult Details(int id)
        {
            return View();
        }

        // GET: MoviesController/Create
        public ActionResult Create()
        {
            return View();
        }

        // POST: MoviesController/Create
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Create(IFormCollection collection)
        {
            try
            {
                return RedirectToAction(nameof(Index));
            }
            catch
            {
                return View();
            }
        }

        // GET: MoviesController/Edit/5
        public ActionResult Edit(int id)
        {
            return View();
        }

        // POST: MoviesController/Edit/5
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Edit(int id, IFormCollection collection)
        {
            try
            {
                return RedirectToAction(nameof(Index));
            }
            catch
            {
                return View();
            }
        }

        // GET: MoviesController/Delete/5
        public ActionResult Delete(int id)
        {
            return View();
        }

        // POST: MoviesController/Delete/5
        [HttpPost]
        [ValidateAntiForgeryToken]
        public ActionResult Delete(int id, IFormCollection collection)
        {
            try
            {
                return RedirectToAction(nameof(Index));
            }
            catch
            {
                return View();
            }
        }
    }
}

App is not yet functional since there is no data to show, let us next create some data!