0

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>
8
  • What is the problem in writing like what you have in your question ? Commented Jun 14, 2012 at 13:30
  • I just want to another style of view layout. Commented Jun 14, 2012 at 13:45
  • Then write markup like above and do it. What is stopping you ? Commented Jun 14, 2012 at 13:48
  • I want the asp.mvc to generate this code for me automatically. Commented Jun 14, 2012 at 13:49
  • So mention/ask " How to create custom scaffolding template" That will get you more answers i guess. Commented Jun 14, 2012 at 13:53

2 Answers 2

1

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)

Scaffold CustomTemplate View Edit

Then it will create a copy in your project which you can then modify and use as you wish.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. This is exactly what I want. My poor English is a obstacal for me to put the question clear.
0

Some other guys also asked this question. Because I use different key words in my question, I didn't find these questions until now.
a similar question on stackoverflow
T4 Templates: A Quick-Start Guide for ASP.NET MVC Developers
ASP.Net MVC - T4 Fun
MvcScaffolding: Overriding the T4 Templates

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.