Say I have the following models:
public class Item
{
public int Id{ get; set; }
public ItemDescription ItemDescription{ get; set; }
}
public class ItemDescription
{
public int Id{ get; set; }
public int Revision{ get; set; }
public string Test{ get; set; }
}
I run the following in the package-manager:
Scaffold Controller Item
to generate some views and stuff... but it appears that the scaffolder ignores any complex/non-scalar data types and consequently generates views that are of little use.
I am wondering if it is possible to instruct the scaffolder to be a little more intelligent about things. Here's what I would like to happen:
EditorFor
to leverage these templatesAll the code to make this happen seems to be generated by the scaffolder, but is structured in a way that surprises me, with _CreateOrEdit.cshtml
"templates" generated in the folder associated with the view. To me, this suggests that the scaffolder generates code that would not be ideally suited to a more recursive way of generating views for models.
Are my expectations way off, or am I missing something?
You can find the T4 Templates that Visual Studio uses to generate the Code in
YourPathToVisualStudio2010\Common7\IDE\ItemTemplates\CSharp\Web\MVC 4\CodeTemplates
change the templates you need to solve your problem in general. Another thing you can do is to create a template and add them to your particular project / solution.
Check out the great Scott Hanselman - T4 (Text Template Transformation Toolkit) Code Generation - Best Kept Visual Studio Secret post.
I really encourage you to read the links in my "more information" section.
Have a nice day!
Since a few days the whole (not only mvc) microsoft webstack (of love, thx scott hanselman for this term ;)) is open source on codeplex ASP.NET Webstack. Check it out!
MVC4 is not in RTM Version, but maybe you are interested in.
Recipes for Code Generation in Visual Studio (MVC4)
The new Recipes feature enables Visual Studio to generate solution-specific code based on packages that you can install using NuGet. The Recipes framework makes it easy for developers to write code-generation plugins, which you can also use to replace the built-in code generators for Add Area, Add Controller, and Add View. Because recipes are deployed as NuGet packages, they can easily be checked into source control and shared with all developers on the project automatically. They are also available on a per-solution basis.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With