I have two MVC views ... one for displaying details and one for editing values. They use almost the same templates, except that DisplayFor changes to EditorFor when switching to viewing the editor. How can I reuse the base layout structure in a view so that if I need to change the main layout, I need to do this in only one place, and not in multiple views?
Here is an example of the table used in the display view:
<table> <tr> <td class="label">First Name:</td> <td class="field">@Html.DisplayFor(x => Model.FirstName)</td> </tr> <tr> <td class="label">Last Name:</td> <td class="field">@Html.DisplayFor(x => Model.LastName)</td> </tr> <tr> <td class="label">Email:</td> <td class="field">@Html.DisplayFor(x => Model.Email)</td> </tr> </table>
source share