Scaffold the movies controller
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
MoviesController
generatedWe 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!
Last updated