views:

160

answers:

2

I am facing an issue while showing the partial view in div with updatetargetid property of Ajax.ActionLink. This is my controller-

    [HandleError]
    public class HomeController : Controller
    {
        static NumberViewModel model = new NumberViewModel();

        public ActionResult Index()
        {

            model.IsDivisibleBy3 = (model.CurrentNumber % 3 == 0);

            if (Request.IsAjaxRequest())
            {
                return PartialView("ViewUserControl1", model);
            }

            return View();
        }

        [ActionName("Increment")]
        public ActionResult Increment()
        {
            model.CurrentNumber++;
            return RedirectToAction("Index");
        }
    }

My Index view -

  <%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Home Page
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <script type="text/javascript">

        function ShowResult() {
            var windowWidth = document.documentElement.clientWidth;
            var windowHeight = document.documentElement.clientHeight;
            leftVal = (windowWidth - 655) / 2;
            topVal = (windowHeight - 200) / 2;       

            $('#result').css({
                "left": leftVal,
                "top": topVal
            });
            $('#background').fadeIn("slow");
        }


    </script>
    <div id="background" class="hiddenDiv">
        <div id="result" class="popupBox">
        </div>
    </div>
   <%= Ajax.ActionLink("Show", "Index", new AjaxOptions() { UpdateTargetId="result", OnComplete="ShowResult", HttpMethod="Get" })%> 
   <%= Html.ActionLink("Increment","Increment") %>

</asp:Content>

This works in FF but not in IE6-IE8.

IE Scenario- So when I Click on 'show', first time it shows '0 is divisible by 3'. if click 'Increment', the number is now 1 and is not divisible by 3. Now if I click on 'show' it shows '0 is divisible by 3'.

After keeping debug points in VS, I found- second time the request does not go to the server at all. Resulting in not updating the updatetargetid div.

Does anybody face this issue before?

+1  A: 

ie is caching dubplicate request just add this to your action method:

        Response.CacheControl = "no-cache";
        Response.Cache.SetETag((Guid.NewGuid()).ToString());

so you will have:

[ActionName("Increment")]
    public ActionResult Increment()
    {
        Response.CacheControl = "no-cache";
        Response.Cache.SetETag((Guid.NewGuid()).ToString());
        model.CurrentNumber++;
        return RedirectToAction("Index");
    }
KP
Excellent! Thanks KP.
Morin
A: 

If somebody stumbles upon this, here is a another good answer - http://stackoverflow.com/questions/1160105/asp-net-mvc-disable-browser-cache

Morin