Saturday, December 21

ASP.NET Scaffolding- Visual 2013

Introduction: ASP.NET Scaffolding is a code generation framework for ASP.NET Web applications. Visual Studio 2013 includes pre-installed code generators for MVC and Web API projects.Scaffolding helps to add code quickly that interacts with data.It reduces significant amount of time to develop standard data operations in project.

Steps:

Open Visual studio 2013 and create 2013 ASP.net Web application. Add a name and select a path to save this project.

Next select MVC template.



Database:

Add data : View- Server explorer. 


Right click “Data Connection” node ->select "Add Connection" and then enter your server name. Test connection and then click “ok”.



 It’ll create a database as your servername.master.db under “Data connection” node. 
 Right click on your database name and select “query” . It opens up sql window. Add the following query and press “ctrl+shift+E” to execute the query. It’ll create a “Book” table and add three records.



Model:
In solution explorer right click “Models” folder and then select “Add” and then “New Item”. It’ll open “Add New item” window. Select “data” and “Ado.net Entity Data Model” and click “Add”. 


Select  “Generate From Database” option from “Entity data Mode wizard” and hit “next”. 


Select data connection you created and save this connection and click “next”. Select “Tables” option in next screen and click “finish”.

The "Models" folder should look like this:


Controller:
 Right click “controllers” folder and then select “add” and then select “new scaffolded item”. Select “MVC5 controller with Views, using Entity Framework”


View:
Compile the project and  find your folder under the “views” folder in solution explorer. Right click on “index.cshtml” and select “view in browser”.


Output:

No comments:

Post a Comment