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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:33:47+00:00 2026-05-19T17:33:47+00:00

I am developing a website using Asp.Net MVC framework. We need to add general

  • 0

I am developing a website using Asp.Net MVC framework. We need to add general user information across a number of pages, in a similar way to the reputation bar at the top of stack overflow.

I consider it important that there should be no overhead added to the creation of a controller method in order to add this extra information to the view. This excludes the option of passing this info in the ViewData object, or amending the ViewModels to accept the reputation field as it would result in every controller looking like this:

public ActionResult Index()
{
    ViewData["reputationScore"] = GetUsersReputation(userId);

    // main controller logic here
}

If this is used across 90% of the pages on a site, it could be quite time consuming to alter if we also wanted to display the users badge count.

I can think of 4 solutions to this

Use Master pages
Retrieve the user reputation in the master page code behind, and put the mark up for the reputation in the master page mark up.

Disadvantages:

  1. This seems to be moving away from everything that MVC represents.
  2. I have been looking at moving to using alternative view engines (e.g. razor) I am not sure how well these will mix.
  3. It tends to restrict the layout of the reputation – hard to put it in the middle of the page.

Extend HtmlHelper to add a GetUsersReputation method
This seems to be a slight violation of what the Html object should be used for – it is not just rendering output, but hitting the database. I can’t think of any other significant issues with this other than the violation of the metaphor.

Override the System.Web.Mvc.ViewPage
Overriding Viewpage to expose an object in addition to Html that can be used to call a selection of methods that access the database. Make sure that extension methods can be added in the same way as HtmlHelper, so that as and when new methods are needed it can be extended appropriately. This could allow us to write something like:

<% DataAccess.GetUsersReputation() %>

Create a base generic view model
Rather than passing your view model straight to the view, wrap it in a base view model that can hold all the methods you need:

public ActionResult Index()
{
    MyViewModel viewCoreInfo = model.GetData();

    return View(new BaseViewModel<MyViewModel>(viewCoreInfo));
}

BaseViewModel can expose all the properties that you need for extra information required on the web page. e.g. UsersReputation (it could either query the database in the constructor, or load the data when the property is accessed). I think this maintains the MVC metaphor better, but is a little cumbersome.

  1. Has someone else come up with a better solution
  2. Which is best – if you have used them have they been effective /problematic?
  • 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-19T17:33:48+00:00Added an answer on May 19, 2026 at 5:33 pm

    Since you mentioned the possibility of moving to the razor view engine, I think that THIS blog post by ScottGu might be of interest.

    He discusses using ‘sections’ with razor that will alow you to create a section on your Layout(“Masterpage”) that you can load with addition content. Creating your SO style info bar in this manner would be clean and simple.

    EDIT:

    As far as rendering partial views as per the comments below…the new mvc music store tutorial has some examples.

    In this case they are using Html.RenderAction. Html.RenderPartial is another option.
    The differences are outlned in this question but im sure there are other resources on the net.

    Your controller would just return a partial view as such:

     return PartialView();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.