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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:14:19+00:00 2026-05-24T20:14:19+00:00

I have this controller function that returns cpu stats: public ActionResult GetStats() { Random

  • 0

I have this controller function that returns cpu stats:

        public ActionResult GetStats()
        {
            Random rand = new Random();
            ViewData["cpu_temp"] = rand.Next(0, 100) + "%";

            return View();
        }

And with a view it works 100%. Bu tI’m wondering if I could shorten the process, and just do something like:

        public ActionResult GetStats()
        {
            Random rand = new Random();

            something.writeline(rand.Next(0, 100) + "%");
        }

Just so I can create controllers and not care about views for simple simple simple output 😀

FIX, after a tip by Jamie Dixon i came up with this solution:

        public ActionResult GetStats()
        {
            Random rand = new Random();
            ViewData["cpu_temp"] = rand.Next(0, 100) + "%";

            return Json(ViewData, JsonRequestBehavior.AllowGet);
        }

Works as intended 😀

  • 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-24T20:14:19+00:00Added an answer on May 24, 2026 at 8:14 pm

    It all depends on where you want to view the data.

    If you want to view the data in your web browser through a web page then you’ll need to return a view.

    If you just want to see the data you could output it to the debug console with

    Debug.WriteLine(mystring);
    

    Alternatively you could send it to the browser in any number of formats that can be downloaded by the user (JSON, XML, Text file) that won’t require a view.

    The key point here is that if you want the user to view the information in their browser in a way that’s likely to show up for them, you’re going to want to use a View.

    UPDATE

    To return a JSON object you can simply return JSON(object).

    return JSON(new {foo = "foo", bar = "bar"});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this function on my controller (Im using CodeIgniter) that reads the database,
I have an action like this: public class News : System.Web.Mvc.Controller { public ActionResult
Basically I have this In my Asp.net controller public ActionResult RenderMyView() { data =
I currently have a controller method that returns a JsonResult: public JsonResult EditField(int FieldID,
I am getting some unexpected behavior from Html.EditorFor(). I have this controller: [HandleError] public
I have this in my controller: MyTestViewModel asdf = new MyTestViewModel { SomeTestDate =
I have a controller action that checks this.User.Identity.IsAuthenticated What do you suggest how to
I have a controller named sales_controller at this controller I got a function in
I have the following controller code that returns a Json list object to my
I have a function that returns a string of HTML code for a jQuery

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.