Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6939669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:39:06+00:00 2026-05-27T12:39:06+00:00

I have two MVC views… one for displaying details and one for editing the

  • 0

I have two MVC views… one for displaying details and one for editing the values. They use almost identical templates with the exception that the DisplayFor is changed to the EditorFor when switching to the editor view. How can I reuse the my base layout structure in the view so that if I need to change the basic layout, I only have to do it in one location and not multiple views?

Here’s a sample 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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T12:39:07+00:00Added an answer on May 27, 2026 at 12:39 pm

    You could add a Mode property to your view model:

    public bool IsInEditMode { get; set; }
    

    Then, your controller can use the same view & model, just setting this property accordingly. Your view would end up like:

    <table>
      <tr>
        <td class="label">First Name:</td>
        <td class="field">
            @if (!Model.IsInEditMode)
            {
                @Html.DisplayFor(x => Model.FirstName)
            }
            else
            {
                (render EditorFor plus any validation helpers)
            }
        </td>
      </tr>
      ...etc...
    </table>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an MVC 3 page that has two partial views, one for Items
I have two ASP.NET MVC web applications. One of them logs unhandled exceptions to
I have two radio buttons on my MVC form that I use to hide
I am new to MVC. I need to have two views (for same logic)
We have two WebApplication in one MVC solution, one for Desktop and the other
I have two views which will both use the same Controller method: //webServiceController.cs //The
In my Asp.net MVC app, I have two methods on a controller, one for
Let say I have two methods in MVC 4 Web API controller: public IQueryable<A>
I have two buttons on my MVC form: <input name=submit type=submit id=submit value=Save />
I have two instances of an Address.ascx control in an ASP.NET MVC page. <h1>Shipping

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.