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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:21:00+00:00 2026-06-06T14:21:00+00:00

. Dear Dev Guys :) I’m learning ASP.NET MVC3 and I’m stuck when I

  • 0

.
Dear Dev Guys 🙂

I’m learning ASP.NET MVC3 and I’m stuck when I use Response.WriteSubsitution() method.

Every time I try to use it in the page, the substitued text always appears on top of the page (screenshot here).

Considering I have the following code in my controller:

public class HomeController : Controller
{
        public ActionResult Index()
        {
            ViewBag.Message = "Welcome to ASP.NET MVC!";
            return View();
        }

        [OutputCache(Duration=20)]
        public ActionResult About()
        {
            ViewBag.Date = DateTime.Now;
            return View();
        }
}

Code in About.cshtml :

@using MvcApplication1;
@{
    ViewBag.Title = "About Us";
}

<h2>About</h2>
<p>
    Date : @ViewBag.Date<br />
    Random Substitued number : @{ Response.WriteSubstitution(MvcApplication1.Helpers.Test); }
</p>

My Helper class:

namespace MvcApplication1
{
    public static class Helpers
    {
        public static string Test(HttpContext context)
        {
            Random r = new Random();
            return r.Next(0, 10).ToString(CultureInfo.InvariantCulture);
        }
    }
}

Did I miss something ?

Thanks !

EDIT with solution:

I solve the issue with the @Darin Dimitrov’s solution.

For people in the same case of me, this is my new code.

My controller:

[DonutOutputCache(Duration = 10)]
        public ActionResult About()
        {
            ViewBag.Date = DateTime.Now;
            return View();
        }

        public string RandomNumber()
        {
            Random r = new Random();
            return r.Next(0, 10).ToString(CultureInfo.InvariantCulture);
        }

MvcDonutCaching implements the class DonutOutputCacheAttribute we have to use instead the build-in OutputCacheOutput.

My View :

@using MvcApplication1;
@{
    ViewBag.Title = "About Us";
    Layout = "~/Views/Shared/Mobile/Layout.cshtml";
}

<h2>About</h2>
<p>
    Date : @ViewBag.Date<br />
    Random Substitued number : @Html.Action("RandomNumber", true)
    @Side
</p>

The package overloads Html.Action method to control the cache 🙂

Thanks all people that feed this thread.

  • 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-06T14:21:02+00:00Added an answer on June 6, 2026 at 2:21 pm

    I’m learning ASP.NET MVC3 and I’m stuck when I use Response.WriteSubsitution() method.

    Forget about this method in ASP.NET MVC 3 as Phil Haack explains. Simply don’t use it. If you wanna achieve donut caching in ASP.NET MVC 3, the framework has nothing to offer you.

    There are third party packages that could enable this functionality if you don’t want to roll your own.

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

Sidebar

Related Questions

Dear all how could im set response status in Asp.net Web service method ?
Dear Stackoverflowers, I am trying to build a simple web application in ASP.NET where
dear all i want to know how to submit asp.net form data using jquery
dear all..i'm newbie at time picker. can you tell me how to use jquery
Dear experts, I am quite new to javascript and I often see coders use
dear all.. i'm new to ajax timer, since someone tell me to use it
dear i am confused the use of content provider in android applications.i go through
dear all.. i have a DB which built use Mysql. for this case, i
Dear Stacktoverflow, can you show me an example of how to use a QScrollBar?
Dear all: In advance, thank you for your time. Lately, I have decided to

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.