3

my problem is when I deleted a row and after delete the row it'll hidden in my list and when I use IE and F5 to refresh page but this row still display. chorme and firefox work fine.

ListView :

@model  IEnumerable<PG.Admin.Models.TimeSheetHeaders.TimeSheetHeaderViewModel>

@{
   ViewBag.Title = "";
   Layout = "~/Views/Shared/_Layout.cshtml";
}

@Scripts.Render("~/Scripts/jquery.unobtrusive-ajax.js")

<div id="unobtrusive">
    @Html.Partial("_TimeSheetList", Model)
</div>

_ListTimeSheet (partial view)

@model PagedList.IPagedList<PG.Admin.Models.TimeSheetHeaders.TimeSheetHeaderViewModel>
@using PagedList.Mvc;

        <table class="table table-striped">
        <tbody>

            <tr>
                <th>
                    @Html.DisplayNameFor(model => model.First().Date)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.First().PGId)
                </th>
                <th>
                    @Html.DisplayNameFor(model => model.First().OutletID)
                </th>
                <th></th>
            </tr>

            @foreach (var group in Model)
            {
                <tr>
                    <td>@Html.DisplayFor(model => group.Date)</td>
                    <td>@Html.DisplayFor(model => group.PGId)</td>
                    <td>@Html.DisplayFor(model => group.OutletID)</td>
                    <td>
                        @Html.ActionLink("Delete", "DeleteTimeSheetConfirmed", new { id = group.Id }, new { @id = group.Id, @class = "delete-timesheet" })
                    </td>
                </tr>
            }
        </tbody>
    </table>

    <div class="dataTable-paging">
        <div class="row">
            <div class="col-xs-6">
                <div class="paging-info">
                    Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
                </div>
            </div>
            <div class="col-xs-6">
                <div class="paging-content">
                    @Html.PagedListPager(Model, page => Url.Action("GroupListTimeSheet",
                         new { page, key = ViewBag.CurrentFilterKey, currentFilter = ViewBag.CurrentFilter }),
                                   PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new AjaxOptions() { HttpMethod = "GET", UpdateTargetId = "unobtrusive" }))
                </div>
            </div>
        </div>
    </div>

<script type="text/javascript">

    $('.delete-timesheet').on("click", function (e) {
        var flag = confirm('delete ?');
        if (flag) {
            e.preventDefault();
            var id = e.target.id;
            $.ajax({
                url: '@Url.Action("DeleteTimeSheetConfirmed", "TimeSheet")',
                type: 'POST',
                data: { id: id },
                dataType: "json",
                cache: false,
                success: function () {
                    $("#" + id).closest('tr').remove();
                },
                error: function () {
                    alert('Error!');
                }
            });
        }
        return false;
    });
</script>

Controller:

     public ActionResult GroupListTimeSheet(string key, string searchName, string currentFilter, int? page)
    {
        var groupTimeSheet = _timeSheetService.GroupTimeSheetByTimeSheetHeader().ToListViewModel();

        if (searchName != null)
        {
            page = 1;
        }
        else
        {
            searchName = currentFilter;
        }

        ViewBag.CurrentFilter = searchName;
        ViewBag.CurrentFilterKey = key;

        if (!String.IsNullOrEmpty(searchName) && key == "pgcode")
        {
            groupTimeSheet = groupTimeSheet.Where(m => m.PGId.Contains(searchName)).ToList();
        }

        if (!String.IsNullOrEmpty(searchName) && key == "quancode")
        {
            groupTimeSheet = groupTimeSheet.Where(m => m.OutletID.Contains(searchName)).ToList();
        }

        if (!String.IsNullOrEmpty(searchName) && key == "date")
        {
            groupTimeSheet = groupTimeSheet.Where(m => Convert.ToString(m.Date).Contains(searchName)).ToList();
        }

        int pageSize = 15;
        int pageNumber = (page ?? 1);

        if (Request.IsAjaxRequest())
        {
            return (ActionResult)PartialView("_TimeSheetList", groupTimeSheet.ToPagedList(pageNumber, pageSize));
        }
        else
        {
            return View(groupTimeSheet.ToPagedList(pageNumber, pageSize));
        }
    }

        [HttpPost]
        public ActionResult DeleteTimeSheetConfirmed(Int64 id)
        {
            var timeSheetHeader = _timeSheetService.GetTimeSheetHeaderById(id);

            if (timeSheetHeader == null)
                return RedirectToAction("Index");

            _timeSheetService.DeleteTimeSheet(timeSheetHeader);

            return Json(true, JsonRequestBehavior.AllowGet);
        }

TimeSheetService:

public IQueryable<TimeSheetHeader> GroupTimeSheetByTimeSheetHeader()
    {
        var groupTimeSheet = from tsh in _timeSheetHeaderRepository
                                 .IncludeTable(
                                    m => m.TimeSheetDetails,
                                    m => m.PGProfile,
                                    m => m.Quan,
                                    m => m.WorkType).OrderByDescending(m => m.Date)
                             select tsh;
        return groupTimeSheet.AsQueryable();
    }
2
  • Do you think IE is caching the result? Can you post your HTTP headers when requesting in IE please. Commented Jul 30, 2015 at 9:34
  • thanks @JamieRees I have resolved Commented Jul 30, 2015 at 10:35

1 Answer 1

2

Sounds like your partial view is caching.

For a partial view add [OutputCache(Duration=1)] to the action (for some reason 0 is not allowed on a partial view).

For a full view there are several options

[OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")]

or just

[OutputCache(Duration=0)]
Sign up to request clarification or add additional context in comments.

12 Comments

Hi @TrueBlueAssie I have tried and your solution it could not resolve my problem
@Khiem Nguyen: If you CTRL-F5 the browser, does it show the deleted record? If so the record is not being deleted.
@TrueBlueAssie I have tried CTR+F5 but It still display agian. This problem only occurs when I click to next page or previous page. If first time load page and don't click to next page it work fine.
Please show the action method used to display this page too. It may be the way the models are retrieved, but that code is missing.
OK, that provider just looks like an Entity Framework wrapper, so should not be caching results.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.