Terminologies in MVC: Part 3 (Scaffolding)

Hello Geeks!

So just go through these, until I present another article in the series: "MVC for Beginners".

Getting a Theme

To access previous articles, kindly go through these articles.

Scaffolding | Model

Scaffolding in ASP.NET MVC can generate the base code you need for Create, Delete, Update, and Delete (CRUD) operations in MVC for your application. It is actually a template. You just need to select one template among the others and based on that template the required code for the CRUD operations will be generated for you.

The Scaffolding is smart, it knows all these things.

  • How to name your Controller
  • How to Name Your View
  • What code needs to be in a component
  • Where to place all these segments in the project
  • How each component will behave

(You don't need to worry about any of these. Scaffolding will do all that for you.)

Customizing Scaffolding

Everyone loves their own way of executing or performing a task. MVC understands this very well, that's why, like nearly everything else in MVC, if you don't like the default scaffolding behavior, you can always customize or replace the code generation to create your own development environment.

There are several Scaffolding templates available in the MVC framework for several code generation strategies but in case don't even like any of them then you can always find alternative scaffolding templates through the NuGet repository in your MVC framework. Use the following procedure for that.

  • Go to NuGet
  • Search for "Scaffolding"
    Scaffolding
  • Select template
    Select template

The NuGet repository contains several scaffolding templates to generate code using specific design patterns and technologies.

But still, if you didn't find the one you are looking for, then you can create your own from scratch.

Key Note. Scaffolding is not required to build an application, it is just a construction work that saves you time. So, the choice is yours.

Available Options

  1. Empty Template
  2. Controller with Empty Read/Write Actions
  3. API controller with Read/Write Actions
  4. Controller with Read/Write Actions and Views (using Entity Framework)

(These aren't all the templates, just some basic templates available in the MVC framework.)

Scaffolding Templates

As I mentioned earlier in this article, Scaffolding is "Construction Work". Now in this section, I'll be discussing what actually I mean by that construction work. So let's explore all the content of construction.

Construction Work

  • Create: It creates a View that helps in creating a new record for the Model. It automatically generates a label and input field for each property in the Model.
  • Delete: It creates a list of records from the model collection along with the delete link with the delete record.
  • Details: It generates a view that displays the label and an input field of each property of the Model in the MVC framework.
  • Edit: It creates a View with a form that helps in editing the current Model. It also generates a form with a label and field for each property of the model.
  • List: It generally creates a View with the help of an HTML table that lists the Models from the Model Collection. It also generates an HTML table column for each property of the Model.

Adding a Scaffold Item to MVC

Use the following procedure to do it.

  • Adding a Controller
    Adding a Controller
  • Choosing a Scaffold Template
     Scaffold Template
  • Provide a name to your Controller
  • A close View
    Close View

Pin Points

  • Scaffolding is not required to build an application
  • It just creates some sort of code for you
  • Can't generate an entire application for you
  • You can customize it
  • You can always create your own
  • Reduce some boring development work

Summary

I hope this was helpful.

A few tips from my side are that if you guys really want to become familiar with MVC then,

  • Take your time
  • Do as much practice as you can (implementation)
  • Try to "learn" things, don't just "study" (I mean it)
  • Try to discuss things with friends, colleagues or in forums (C# Corner)
  • If you experience any problems, then your queries are welcome.

I hope you guys enjoyed this.

Happy Coding!


Similar Articles