Click here to Skip to main content
Sign Up to vote bad
good
See more: C#MVC3EF4.0
Microsoft has provided a cool feature for generating controller and views using scaffolding of templates and you can do it by just right clicking on the controller's folder, say add controller and add then can specify the data context class,modal and then select template and click on Add buttton to generate the respective controllers and strongly typed views,but can we automate this process so that I don't have to manually go through the above steps for each and every modal and rather we can have some custom template for generating the controller and views for all the modals at one go?
 

Mayank Singh
Posted 25 May '12 - 20:21
Edited 10 Dec '12 - 22:35

Comments
Keith Barrow - 27 May '12 - 9:26
You could create a macro or a project template to do part of the work, but you'd still need to supply the macro/template with a database to generate from first. It is this last point that takes up most of the time. Why do you need to automate this so heavily- it might help me understand your problem better.
mayankps - 30 May '12 - 2:48
Tnx for the reply keith,I just want to reduce the repetitive work that I normally do, when I create admin web application to handle master tables in most of the place things remain same, and hence I want to just focus on tt file instead of focusing on individual pages that is write once and use it every where kind of approach, and by doing this I would be able to generate controllers and views for all the models and then my team have to just focus on further customization or logic implementation required for individual views. Hope this answers your question

2 solutions

Use T4 Template
T4 is a general-purpose templating engine you can use to generate C# code, Visual Basic code, XML, HTML, or text of any kind. The first step in using T4 is to create a template file, which is a mix of literal text, code, and processing directives. The T4 template processor will transform this file into a text file of the desired type by executing the code and processing directives inside.
 
The below link helps you to develop custom template for entityframework using T4 template
http://msdn.microsoft.com/en-us/data/gg558520.aspx[^]
 
Hope this helps
  Permalink  
try using Dynamic Data Entities framework.
 
You can generate Entities and screens are generated using scaffolding.
  Permalink  
Comments
mayankps - 30 May '12 - 3:00
Hi Madhukar tnx for the reply,the above approach will generate the pages on the fly for each model and I don't want that, instead I want to generate controllers and view for all the models using MVC Scaffolding and then I want to work on them for further customization,but the problem is currently in database first approach we don't have the option for scaffolding all the models at one go.

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 464
1 Mahesh Bailwal 373
2 Maciej Los 215
3 CPallini 175
4 Rohan Leuva 175
0 Sergey Alexandrovich Kryukov 9,402
1 OriginalGriff 7,204
2 CPallini 3,933
3 Rohan Leuva 3,211
4 Maciej Los 2,743


Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 19 Dec 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid