MVC Ajax刷新间隔文本突出显示更改值

时间:2015-06-20 09:30:53

标签: jquery ajax asp.net-mvc

我制作了一个带有局部视图的MVC视图,每隔X秒刷新一次。这样做很好,但是:我想强调正在改变的价值观。因此,如果只有1行正在改变,我想突出显示该行几秒钟。像这样:http://domajax.com/documentation/data-highlight-color(成功和错误)。

我的主要观点:

@using MovieStore.Domain.Entities

@model IEnumerable<IGrouping<Movie, TimeTable>>
@{
    ViewBag.Title = "Actuele bezetting";
}

<h2>Bezetting voor vandaag</h2>

<div id="timetabel">
    @{ Html.RenderPartial("_TimeTable", Model); }
</div>
<script type="text/javascript">
    window.setInterval(function () {

        $("#timetabel").load('@(Url.Action("GetTimeTable","TimeTable",null, Request.Url.Scheme))');

    }, 5000);
</script>

部分观点:

@using MovieStore.Domain.Entities

@model IEnumerable<IGrouping<Movie, TimeTable>>

<table class="table">
    <tbody>
        @foreach (var group in Model)
        {
            <tr>
                <td>
                    <div class="col-lg-9">
                        <h4>@group.Key.MovieName</h4>
                        <table class="table">
                            <tbody>
                                <tr><td>Starttijd</td><td>Vrije plaatsen</td></tr>

                                @foreach (var tt in group)
                                {
                                    <tr>
                                        <td>@tt.StartTime.ToShortTimeString()</td>
                                        <td>@tt.SeatsAvaible</td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    </div>

                </td>
            </tr>
        }
</table>

控制器:

public async Task<ActionResult> Index()
        {
            var model = await GetTimeTabelModel();
            return View(model);
        }

        public async Task<ActionResult> GetTimeTable()
        {
            var model = await GetTimeTabelModel();
            return PartialView("_TimeTable", model);
        }


        private async Task<IEnumerable<IGrouping<Movie, TimeTable>>> GetTimeTabelModel()
        {
            return timetablerepo.TimeTables.Where(tt => tt.StartTime.Date == DateTime.Now.Date).GroupBy(tt => tt.Movie);
        }

0 个答案:

没有答案