Scaffolding in .NET Core (generate API controllers – CRUD (or MVC controller with views in necessary)

Right click on ‘Controllers’ folder –> Add –> New Scaffolded Item…

For api controller without views select ‘API Controller with actions, using Entity Framework’ and click ‘Add’.
If MVC then choose ‘MVC Controller with views, using using Entity Framework’

On next view select your model (you need create model before generate code) and select data context (if you don’t have already existing one then you can create clicking ‘+’ sign)

Click ‘Add’ and it should start generate code (controller with CRUD to your model).

In older project you can get error trying to generate code, could be problem with e.g. unupdated packages: Microsoft.EntityFrameworkCore.SqlServer, Microsoft.EntityFrameworkCore.Design’.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: