我有一个控制器
public class AccountDetailsController : Controller
{
private readonly IAccountStatsRepository _accountStatsRepository;
public AccountDetailsController(IAccountStatsRepository accountStatsRepository)
{
_accountStatsRepository = accountStatsRepository;
}
public ActionResult Details(string accountEmail)
{
var stats = _accountStatsRepository.Get(accountEmail);
var accountDetailsViewModel = new AccountDetailsViewModel
{
Email = accountEmail,
Money = stats.TotalCredits
};
return View(accountDetailsViewModel);
}
[OutputCache(NoStore = true, Location = OutputCacheLocation.Client, Duration = 3)] // every 3 sec
public ActionResult GetLatestLogging(string email)
{
//if (email == null || email != null)
//{
var list = new List<LogViewModel>();
return PartialView("LatestLoggingView", list);
//}
}
}
和视图
@using FutWebFrontend.ViewModels
@model AccountDetailsViewModel
@{
ViewBag.Title = "Details";
}
<h2>@Model.Email</h2>
<div>
<h4>Account details</h4>
Money @String.Format("{0:0,0}", Model.Money)
</div>
<div id="loggingstream">
@Html.Partial("LatestLoggingView", new List<LogViewModel>())
</div>
<hr />
<dl class="dl-horizontal"></dl>
<p>
@Html.ActionLink("Back to List", "index", "AccountControl")
</p>
<script type="text/javascript">
$(function() {
setInterval(function () { $('#loggingstream').load('/AccountDetails/GetLatestLogging/@Model.Email'); }, 3000);
});
</script>
但是当我进入我的页面并在GetLatestLogging中放置一个断点时,没有任何反应 如果我在chrome中点击F12,我会得到“Uncaught ReferenceError:$ is not defined”详情:67
从我可以收集的内容来看,这应该每隔3秒点击我的Get方法,但我必须在某个地方犯了一个简单的错误
答案 0 :(得分:1)
试试这个
$( document ).ready(function() {
setInterval(function () {$('#loggingstream').load('/AccountDetails/GetLatestLogging/@Model.Email'); }, 3000);
});