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 8238685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:53:51+00:00 2026-06-07T19:53:51+00:00

I am currently working on converting an existing webforms application to MVC and am

  • 0

I am currently working on converting an existing webforms application to MVC and am not sure how to design one of the pages. The existing page is 2500 lines of code, and is responsible for displaying several different views of the same information. The following example is just a small piece of this page (a toolbar), but I’m not sure what the best approach is to avoid duplicating code.

Administrator view toolbar:
Save, PDF, Print, Spell Check, Administrative Documents, Employee View Toggle

Manager view of toolbar:
Save, PDF, Print, Spell Check, Employee View Toggle

Employee view of toolbar:
Save, PDF, Print, Spell Check

I have split the application into three different views. They use the same partial views to render the content of the page, but currently each view has it’s own copy of the toolbar. So the HTML elements for Save, PDF, Print and Spell Check are duplicated in each of the views. It would be ideal to have a partial view to render the toolbar, but in order to do that I would need to put some sort of logic in the view to determine if it should show the Employee View Toggle link or the Administrative Documents.

I have also ran into similar problems while developing other new pages. Initially the requirements for different pages have the same element on them that we split into a partial view. After testing and adding more functionality, eventually the partial view needs to be slightly different on each of the pages. Usually it’s just the visibility of the certain controls, but eventually the partial views end up having a bunch of logic in them to check several things to determine if something should be shown.

What is the best approach for dealing with slightly different views where most of the elements are the same?

  • 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-06-07T19:53:53+00:00Added an answer on June 7, 2026 at 7:53 pm

    If it’s just an issue of permissions showing or hiding different parts of the same control/partial view/whatever, I would say just write one and have some code in it to check permissions and conditionally render or don’t render various parts. Something like this:

    <%@ Control Language="C#" %>
    
    This is the toolbar!!
    
    <div class="fake-css-class">
    <%:Html.ActionLink("Save", "Save") %>
    <%:Html.ActionLink("PDF", "Pdf") %>
    <%:Html.ActionLink("Spell Check", "SpellCheck") %>
    <% if (CurrentUser.IsInRole("Admin") { %>
    <%: Html.ActionLink("Administrative Documents", "AdminDocs") %>
    <%} %>
    <% if (CurrentUser.IsInRole("Admin") || CurrentUser.IsInRole("Manager"){
            %>
    <%: Html.ActionLink("Employee View Toggle", "EmpView") %>
    <%} %>
    </div>
    
    <br />
    <br />
    

    EDIT:

    When the logic gets more complicated, add functions to your security code so that you can separate all the logic out into your model/controller and in the view you’re making a single function call. For example something like this:

    public bool Authorize(string controllerName, string actionName) {
    
                bool authorize = false;
    
                foreach(var permission in this.permissions) {
                    if (permission.Matches(controllerName, actionName)) {
                        authorize = permission.Affirmative;
                    }
                }
    
                return authorize;
            }
    

    This way you could have the code outside of the view and simply a single line of code in the view. The above code is just taken out of my current project and used as an example, but you can write whatever complicated logic and put it out in the model or controller so your view stays clean and you aren’t putting business logic in there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently working on converting an existing web application to support an additional
I am currently working on converting an application from access to C# and have
I have an existing ASP.NET web application that I'm converting to MVC 1.0. The
I had a working page with linq to sql and now I'm currently converting
Currently working with converting SQLException error messages into messages that are more useful for
I am currently working on converting a ColdFusion website, using Fusebox framework, to PHP.
I'm currently working on converting an Android app I built natively as an iPhone
I've got a bit of a problem. I'm currently working on converting an old
Currently I'm working on converting object to XML, I notice all object properties are
Currently working on a game, and is converting it to retina. I am using

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.