Hello Geeks!
So just go through these, until I present another article in the series: "MVC for Beginners".
Getting a Theme
For accessing 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 be 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 behaviour, 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 you MVC framework. Use the following procedure for that.
- Go to NuGet
- Search for "Scaffolding"
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
- Empty Template
- Controller with Empty Read/Write Actions
- API controller with Read/Write Actions
- 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.
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 delete record.
Details: It generates a view that displays the label and an input field of the 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 label and field for each property of the model.
List: It generally creates a View with the help of a HTML table that lists the Models from the Model Collection. It also generates a HTML table column for each property of the Model.
Adding a Scaffold Item to MVC
Use the following procedure to do it:
- Choosing a Scaffold Template
- Provide a name to your Controller
- A 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 is that, if you guys really want to become familiar with MVC then:
- Take your time
- Do as much practise 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 problem, then your queries are welcome.
I hope you guys enjoyed this. #Happy Coding