返回首页

局部视图自动刷新:在ASP.NET MVC3问题
中的ASP.NET MVC3的局部视图,必须在每一个特定的时间间隔刷新。
让我们看一看一个典型的ASP.NET MVC3应用的。在HomeController中,有一个动作叫代码>报价显示有趣的软件像下面的每一个新的请求报价???

public class HomeController : Controller

{

    public static string[] quotes = {

        "The first 90% of the code accounts for the first 90% of the development time. 

        "The remaining 10% of the code accounts for the other 90% of the development time",

        "In order to understand recursion, one must first understand recursion",

        "I have always wished for my computer to be as easy to use as my telephone; 

        "my wish has come true because I can no longer figure out how to use my telephone.",

        "The gap between theory and practice is not as wide in theory as it is in practice.",

        "Nine people cant make a baby in a month"

    };



    // other actions



    public ActionResult Quote()

    {

        var r = new Random();

        var rv = r.Next(0, 4);

        ViewBag.Quote = quotes[rv];

        return PartialView("_Quote");

    }

}
??
局部视图em>的_Quote.cshtml有什么比下面的代码:{C}
这整个事情需要无需任何用户交互,每10秒刷新。解
使用setInterval()在客户端,并成立了各自的行动OutputCacheAttribute。双方的持续时间应该是相同的。
在这种观点的相应的脚本,把下面的JavaScript:
// jQuery used



setInterval("$('#quote').load('/home/quote')", 10000); // every 10 sec

在主视图中,创建一个div id为代码>报价喜欢吗???:
在操作方法,设置的OutputCacheAttribute如:{体C3}

回答