This tip discusses command line scaffolding in MVC 6 in Visual Studio 2015 RC.
In this short tip, I will demonstrate how to do controller scaffolding in MVC 6 in the recent Visual Studio 2015 RC. CRUD scaffolding for controllers in MVC 6 in ASP.NET 5 has been moved to command line. In the latest RC of Visual Studio 2015, the .NET Execution Environment (DNX) has been renamed for k or kr.
To start with the scaffolding process, please follow the article below to install DNVM to windows machine:
After installing dnvm, you can run from the command line you can run dnx command, for example to run the web site:
dnx . web
This will run the web site where the web command is defined in project.json file as below:
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls
To create a new controller with CRUD operations can also be done with the dnx command from the prompt. To open the command prompt and go to your MVC 6 project folder where your project.json file is and apply the command to scaffold the new controller and the views as below:
dnx . gen controller -name NameOfController --dataContext DBContextName --model NameOfModel
web command, the
gen command has also been defined in project.json as:
"web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000",
This is will create the controller and the views for CRUD operations.
In particular, I have used Person.cs model class and
MyDBContext as the Database Context, the command was:
dnx . gen controller -name PersonController --dataContext MyDBContext --model Person
After running the command, it generates the controller and views as shown below:
Points of Interest