Mech0z
Mech0z

Reputation: 3647

MVC 5 view not autoupdating partial view

I have a controller

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);
        //}

    }
}

And a View

@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>

But when I go to my page and put a breakpoint in GetLatestLogging then nothing happens If I hit F12 in chrome I get "Uncaught ReferenceError: $ is not defined "Details:67

From what I can gather, this should hit my Get method every 3 seconds, but I must have made a simple error somewhere

Upvotes: 0

Views: 73

Answers (1)

Ignacio Laborde
Ignacio Laborde

Reputation: 1462

Try this

$( document ).ready(function() {
setInterval(function () {$('#loggingstream').load('/AccountDetails/GetLatestLogging/@Model.Email'); }, 3000);
});

Upvotes: 1

Related Questions