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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:53:29+00:00 2026-05-26T02:53:29+00:00

In a nutshell, I would like to simplify some of my MVC pages by

  • 0

In a nutshell, I would like to simplify some of my MVC pages by creating a static class to get the data from a data store of some sort then return one of multiple views based on some internal flags.

internal static class StaticPageContent
{
    internal static ViewModels.Display GetPage(string Map = null, int? ID = null) {...}
    internal static ActionResult ReturnView(ViewModels.CMS.Display vm) {...}
}

Then, in any of my controller actions I could call it something like:

public ActionResult ActionName()
{
    var vm = StaticPageContent.GetPage("/Home");
    return StaticPageContent.ReturnView(vm);
}

Where the ReturnView() method would return one of multiple (shared) views:

internal static ActionResult ReturnView(ViewModels.CMS.Display vm)
{
    if (vm.useLoremIpsum)
        return View("LoremIpsum", vm);
    else
    {
        if (vm.canEdit)
            return View("ViewReadWrite", vm);
        else
            return View("ViewReadOnly", vm);
    }
}

What is the right way of returning a View(…) object from a non-Controller class? The above will not compile as the View(…) is part of the Controller class.


NOTE:
I believe I got something like this working but the demands on my time sent me in another direction. I am hoping to be able to open this project back up to see what I did and post it here. Stay tuned!

  • 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-26T02:53:29+00:00Added an answer on May 26, 2026 at 2:53 am

    Simply put, the right way is to not do it in a static class. (IMO, of course). Especially if you’re getting “data from a data store” – this should not be static.

    In my opinion, create a protected method in a base controller, or use child actions and render them out using Html.Action.

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

Sidebar

Related Questions

In a nutshell: what sort of applications would be benefit most from the dashboard
We have several Visual Studio projects, and we would like to: enable/disable some defines
Nutshell: I launch a thread from my form, then some time later use the
I would like to know, in a nutshell, a summary of the limitations of
In a nutshell My command line Java application copies data from one datasource to
In a nutshell, the app looks up an instruction for something to do from
I'm writing a browser add-on (Chrome and Firefox) which, in a nutshell, does some
I have wrote a web service, in a nutshell it uses openpop to get
I am trying some tutorials on bioconductor; but I get error messages, that I
The book "Unix in a Nutshell" discusses about accessing multiple files on pages 572-573.

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.