如何创建Ajax更新时间?

I'm creating partial view. I need to get number of seconds that have passed since 2012.04.01

public PartialViewResult SitePowered()
{
    var dateTime = new DateTime(2012, 4, 1);
    var totalSeconds = (DateTime.Now - dateTime).TotalSeconds;
    ViewBag.TotalSeconds = totalSeconds;
    return PartialView("SitePowered");
}

view:

<script type="text/javascript">
    $(function () {
        $.getJSON("/Home/SitePowered", null, setTime);
    });
</script>
@ViewBag.TotalSeconds секунд 

but it does not work

You have to do something like this:

Action:

public ActionResult SitePowered()
{
    var dateTime = new DateTime(2012, 4, 1);
    var totalSeconds = (DateTime.Now - dateTime).TotalSeconds;
    return Json(new { seconds = totalSeconds });
}

Client-side:

<script type="text/javascript">
    $(function () {
        $.getJSON("/Home/SitePowered", function(result) {
              // Do something here with result.seconds
              alert(result.seconds);
        });
    });
</script>

Hope it helps.