ASP.NET MVC 3 can generate scaffold code for us(controllers and views). The generated views by default use div and css layout.
But sometimes I need table layout views rather than div (as in default mode). How to generate table layout views like the following code? I also need the column number in a table row can be customerized.
My Question is: how to make asp.net mvc automatically generate talbe layout views for me. And more generally, how to modify the scaffold code template?
<table>
<tr>
<td class="editor-label">
Id
</td>
<td class="editor-field">
@Html.EditorFor(model => model.Id )
@Html.ValidationMessageFor(model => model.Id)
</td>
<td class="editor-label">
name
</td>
<td class="editor-field">
@Html.EditorFor(model => model.Name)
@Html.ValidationMessageFor(model => model.Name)
</td>
</tr>
<tr> ... other fields go here ... </tr>
</table>
I have never taken the time to override the T4 templates, but there are some blog post about the exact way to get to the templates and create/modify with your own layouts. The best example I could find is this blog post by Steve Sanderson
http://blog.stevensanderson.com/2011/04/06/mvcscaffolding-overriding-the-t4-templates/
It appears that you will need to override the Scaffolder “View” and the Create, CreateOrEdit, Edit templates. Once you run the command specified in the above post in the PM console line (see below)
Then it will create a copy in your project which you can then modify and use as you wish.