IE div,updatetargetid 在后续请求中不刷新

发布于 2024-09-10 13:25:47 字数 2144 浏览 5 评论 0原文

我在使用 Ajax.ActionLink 的 updatetargetid 属性显示 div 中的部分视图时遇到问题。 这是我的控制器 -

    [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");
        }
    }

我的索引视图 -

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

这适用于 FF 但不适用于 IE6-IE8。

IE场景- 所以当我点击“显示”时,它第一次显示“0 能被 3 整除”。 如果单击“递增”,则数字现在为 1 并且不能被 3 整除。 现在,如果我点击“显示”,它会显示“0 能被 3 整除”。

在 VS 中保留调试点后,我发现第二次请求根本没有发送到服务器。导致没有更新updatetargetid div。

以前有人遇到过这个问题吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

远山浅 2024-09-17 13:25:47

即正在缓存重复请求只需将其添加到您的操作方法中:

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

这样您将拥有:

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

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");
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文