2

Each time I use Visual Studio to generate a display-template using scaffolding I get something like this:

<fieldset>
    ...
    <div class="display-label">Property</div>
    <div class="display-field">@Model.Property</div>
    ...
</fieldset>

Is there any way to change this template so that it use a HTML definition list instead?

<dl>
    ...
    <dt>Property</dt>
        <dd>@Model.Property</dd>
    ...
</dl>

I know you could use DisplayTemplates, but I want the generated code to be default in all my projects.

Mickel
  • 6,658
  • 5
  • 42
  • 59

3 Answers3

3

Take a look at the following post: http://weblogs.asp.net/scottgu/archive/2009/01/27/asp-net-mvc-1-0-release-candidate-now-available.aspx. It describes customizing the templates. While it was written about Mvc 1 everything still applies

marcind
  • 52,944
  • 13
  • 125
  • 111
  • ok thanks, that seems to be it. However, I cannot locate the "ItemTemplates" folder inside my Visual Studio installation. Any ideas why? I use Visual Studio 2010 Pro... – Mickel Feb 24 '11 at 16:44
  • Thad located under Common7\IDE. In your VS installation directory (also file search is your friend :) – marcind Feb 24 '11 at 16:50
  • I know where they're supposed to be, but they are not there :S Search returns no results for either the folder name or an existing template, like "create.tt". – Mickel Feb 24 '11 at 17:35
  • Should be under a path like this: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\ItemTemplates\CSharp\Web\MVC 3\CodeTemplates\AddView\CSHTML (in MVC 3). If they're not there you might want to try reinstalling the MVC tooling. – marcind Feb 24 '11 at 17:41
2

If you are having trouble finding the item templates you can add them to your project with Nuget: http://blogs.msdn.com/b/joecar/archive/2011/01/06/add-the-asp-net-mvc-3-code-templates-to-your-application-with-nuget.aspx

Joe Cartano
  • 2,997
  • 3
  • 22
  • 40
1

You can accomplish this through T4 templates. Take a look at the explanation in this thread. How do I create my own Scaffold Template in ASP.NET MVC 3?

Community
  • 1
  • 1
Wizard of Ogz
  • 12,543
  • 2
  • 41
  • 43