Scaffolding Syncfusion Controls in Blazor Applications | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (174).NET Core  (29).NET MAUI  (207)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (215)BoldSign  (14)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (66)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (100)Streamlit  (1)Succinctly series  (131)Syncfusion  (915)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (36)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (147)Chart  (131)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (628)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (40)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (507)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (10)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (592)What's new  (332)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Scaffolding Syncfusion Controls in Blazor Applications

Scaffolding Syncfusion Controls in Blazor Applications

We are glad to announce that scaffolding support for Syncfusion Blazor components is now available with our Essential Studio 2019 Vol 4 release.

In this blog, we will explain how to use scaffolding in a Blazor application with the Syncfusion DataGrid control as an example.

What is scaffolding?

Scaffolding is a great way to kick-start model-view-controller (MVC) framework development. It is a code-generation framework for any application. It allows application developers to create the controller/service and Razor view quickly with respect to the existing models in the application.

Scaffolding support for Syncfusion Blazor controls

Developers can be more productive with Syncfusion scaffolding because it will add the necessary data to the controller/service and Razor view using Syncfusion code snippets automatically. The following are the Syncfusion Blazor controls that currently support scaffolding:

Create Model and DB context classes

To perform Syncfusion scaffolding, you should use Model and DB context classes in your application. Please do the following steps to create the Model and DB context classes in your Blazor application:

Step 1: Create a new database and table using SQL Server application, if it does not exist.

Step 2: Open an existing Blazor application project or create a new Blazor application using Visual Studio.

Step 3: Install following NuGet packages in the application:

  • AspNetCore.Mvc.NewtonsoftJson
  • EntityFrameworkCore.SqlServer
  • EntityFrameworkCore.Tools
  • Extensions.Logging.Debug
  • VisualStudio.Web.CodeGeneration.Design

Step 4: To connect your SQL Server, go to View->SQL Server Object Explorer in SQL Server Object Explorer, right-click your database, and then copy the connection string.

Step 5: Open the Package Manager Console by selecting the project and then go to Tools->NuGet Package Manager->Package Manager Console.

Step 6: Execute following commands in the Package Manager Console with the copied connection string:
>Scaffold-DbContext “{Connection String}” Microsoft.EntityFrameworkCore.SqlServer -OutputDir Model -Context “{Db context class name}” -DataAnnotations

Step 7: Now, Model and DbContext classes will be created in the application. Then build the project.

How to use Syncfusion scaffolding

Follow these steps to use Syncfusion scaffolding in a Blazor application:

Step 1: Open an existing Blazor (ServerSide or Hosted) application project or create a new one with the Entity Framework Data Model. Ensure that the application has been compiled once.

Step 2: If the project type is Blazor ServerSide, right-click the Pages folder in the Solution Explorer, click Add, and then select New Scaffolded Item….

Adding New Scaffolded Item from ServerSide project
Adding New Scaffolded Item from ServerSide project

If the project type is Blazor Hosted, right-click the Controllers folder from the {Project Name}.Server project in the Solution Explorer, click Add, and then select New Scaffolded Item….

Adding New Scaffolded Item from Hosted project
Adding New Scaffolded Item from Hosted project

Step 3: In the Add Scaffolddialog, select Syncfusion Blazor Scaffolderand then click Add.

Adding Syncfusion Blazor Scaffolder
Adding Syncfusion Blazor Scaffolder

Step 4: In the Syncfusion UI Scaffolder dialog, select the desired control (DataGrid in our example) to perform scaffolding, and then click Next.

Syncfusion UI Scaffolder control selection dialog
Syncfusion UI Scaffolder control selection dialog

Note: The Scheduler control is not available for Blazor Hosted applications.

Step 5: The Syncfusion UI Scaffolder dialog will be opened for the selected control. Enter the Controller/Servicename and Razorname as application requirements, and then select the required Model Class of the active project and its relevant Data Context Class. Click Next.

DataGrid model configuration dialog
DataGrid model configuration dialog

Step 6: The Syncfusion UI Scaffolder dialog for the selected control feature will open. Select the required features, update the required data field, and then click Add.

For a ServerSide Application, both local data and remote data types will be available.

DataGrid feature selection dialog for ServerSide applications
DataGrid feature selection dialog for ServerSide applications

For a Hosted Application, the remote data type alone will be available.

DataGrid feature selection dialog for hosted application
DataGrid feature selection dialog for hosted application

Step 7: The Controller/Servicefile and the corresponding Razorfiles are generated with the selected features of the Syncfusion control code snippet.

If you select Local Data, the service file and Razor files will be added to the project.

Service and Razor file added
Service and Razor file added

If you select Remote Data, the controller file and Razor file will be added to the project.

Controller and Razor file added
Controller and Razor file added

Step 8: Refer to the following UG links to render the Syncfusion control after performing scaffolding.

WebAssembly AppConfigure Blazor controls using Sycnfusion.EJ2.Blazor NuGet Package

Blazor Server App: Configure Blazor controls using Sycnfusion.EJ2.Blazor NuGet Package

Conclusion

Use Syncfusion scaffolding in your project to add code that interacts with data models. Using it can reduce the amount of time it takes you to develop standard data operations in your project.

Syncfusion provides more than 65 high-performance, lightweight, modular, and responsive Blazor UI controls such as DataGrid, Charts, and Scheduler to ease the work of developers.

For which control are you anticipating scaffolding support? Let us know in the comment section below. You can also contact us through our support forum, Direct-Trac, or our feedback portal. We will implement requests based on the number of customers requesting them.

Tags:

Share this post:

Comments (5)

Does scaffolding support grouped data when using the datagrid?

Hi Alan,

Yes, you can enable the grouping in DataGrid by checking the Grouping checkbox from the feature selection dialog.

HI, it is possible to have this example with the new syncfusion version 18.3 netCore3.1?.. scaffolding.. same example ?.. please .. thanks in advanced.

Hi Bob,

As per your request, we have created the basic Blazor Server application with Database here. After downloading the sample, please follow the below steps to add the Model classes and use the Syncfusion scaffolding

1. Open the downloaded application and go to Tools -> NuGet Package Manager -> Package Manager Console and run the below command

Scaffold-DbContext “Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=\SyncfusionScaffolding\SyncfusionScaffolding\Data\NORTHWND.MDF;Integrated Security=True” Microsoft.EntityFrameworkCore.SqlServer -OutputDir Model -Context “NORTHWNDContext” -DataAnnotations

For ex: Scaffold-DbContext “Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\\Downloads\SyncfusionScaffolding\SyncfusionScaffolding\Data\NORTHWND.MDF;Integrated Security=True” Microsoft.EntityFrameworkCore.SqlServer -OutputDir Model -Context “NORTHWNDContext” -DataAnnotations

2. Then follow the steps under the How to use Syncfusion Scaffolding section in this blog to add the Syncfusion controls through the Syncfusion Scaffolding for your development.

Note: The Syncfusion Scaffolding will be added to the Syncfusion NuGet packages with the latest version from nuget.org by default. If you have the Syncfusion Blazor NuGet packages in your application, the Syncfusion scaffolding will be added to the new NuGet packages with the already available version.

Regards,
Kannan

I know this is really boring and you are skipping to the next comment, but I just wanted to throw you a big thanks – you cleared up some things for me!

Comments are closed.

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed