Click here to Skip to main content
15,440,268 members
Articles / Web Development / HTML
Posted 6 May 2015

Tagged as


10 bookmarked

MVC 6 Controller Scaffolding in Command Line

Rate me:
Please Sign up or sign in to vote.
4.60/5 (5 votes)
6 May 2015CPOL1 min read
Controller Scaffolding in Visual Studio 2015 RC MVC 6 Project


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:

"commands": {
    "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls 

Scaffolding Process

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

Like web command, the gen command has also been defined in project.json as:

"commands": {
    "web": "Microsoft.AspNet.Hosting --server Microsoft.AspNet.Server.WebListener --server.urls http://localhost:5000",
    "gen": "Microsoft.Framework.CodeGeneration"


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

  • New feature of ASP.NET 5


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
Software Developer (Senior)
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

QuestionWhy '.' in dnx command Pin
techbhalla videosgeek6-Jul-16 22:41
Membertechbhalla videosgeek6-Jul-16 22:41 
GeneralMy vote of 5 Pin
Camilo Reyes6-May-15 9:20
professionalCamilo Reyes6-May-15 9:20 
GeneralRe: My vote of 5 Pin
Mostafa Asaduzzaman6-May-15 9:26
MemberMostafa Asaduzzaman6-May-15 9:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.