I am currently watching the 80 minute ASP.NET MVC introduction. Automatically generating views from a model is pretty neat, but it seems to me that that the automatically generated views could be much better. For a start, instead of inputing dates with text boxes, there could be a date control. Additionally, number inputs could be verified client side. There are probably other improvements that could be made as well. Is it possible to automatically generate better views?
+2
A:
You can find the t4 templates used to generate the Views and Controllers in the following directory.
C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 2\CodeTemplates
This may vary depending on your version on Visual Studio.
You can then copy the CodeTemplates directory and all of its contents in to the top directory of your MVC project. This will now override the default templates. You will now be able to edit these templates to generate the code you want.
You should also look at MVC 2 EditorTemplates feature will override how DateTime will be displayed for editing without changing the t4 templates.
Joel Cunningham
2010-06-11 02:16:53
Instead of editing the T4 templates, you should definitely look into the MVC 2 editor templates. There are also MVCContrib input builders and FubuMVC based builders if you want to check out all your options. My convention for DateTime inputs is to use a JQuery date picker in combination with a textbox.
Ryan
2010-06-11 02:31:11