Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
部分视图的Ajax部分更新在ASP.NET MVC2中不起作用_Ajax_Asp.net Mvc 2_Partial Views - Fatal编程技术网

部分视图的Ajax部分更新在ASP.NET MVC2中不起作用

部分视图的Ajax部分更新在ASP.NET MVC2中不起作用,ajax,asp.net-mvc-2,partial-views,Ajax,Asp.net Mvc 2,Partial Views,我在尝试在ASP.NET MVC2中使用部分更新时遇到了一些问题。我想我已经非常仔细地阅读了我在网上找到的教程,但是Ajax部分不起作用。控制器执行它应该执行的操作,没有错误,但是页面不会自动更新。当我刷新页面时,我可以看到我操作的结果 以下是用户控件的代码,该控件应自行更新: <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Ideas.Models.Comment>" %> <s

我在尝试在ASP.NET MVC2中使用部分更新时遇到了一些问题。我想我已经非常仔细地阅读了我在网上找到的教程,但是Ajax部分不起作用。控制器执行它应该执行的操作,没有错误,但是页面不会自动更新。当我刷新页面时,我可以看到我操作的结果

以下是用户控件的代码,该控件应自行更新:

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<Ideas.Models.Comment>" %> <script src="../../Scripts/jquery-1.4.1.js" type="text/javascript"></script> <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script> <script src="../../Scripts/MicrosoftMvcAjax.js" type="text/javascript"></script> <script type="text/javascript">

    function AnimateVotebox() {
        $("#commentbox").animate({ fontSize: "1.5em" }, 400);
    }

</script> <div id="commentbox">
    <div class="display-label">
        <i><%: Html.ActionLink(Model.User1.UserName, "Details", "User", new { id = Model.User1.LoweredUserName.Replace(' ', '-') }, null)%> zegt:</i>
    </div>
    <div class="display-label"><%:Model.text %></div>
        <% bool canPost = Ideas.Helpers.UserHelper.CanPost(HttpContext.Current); %>
        <% if (Model.CommentVotes.Count != 0) %>
        <% { %>
            <div class="display-label"><%= Html.Encode(Model.UpVotes)%> van de 
                <%= Html.Encode(Model.Votes)%> gaan akkoord.</div>
                <% if (canPost)
                   { %>
                <% if (Model.HasVoted((Guid)Membership.GetUser(Context.User.Identity.Name).ProviderUserKey) < 0) %>
                <% { %>Stem:
                    <%= Ajax.ActionLink("-", "VoteComment", "Votes",
                        new { id = Model.id, up = false },
                        new AjaxOptions { UpdateTargetId = "commentbox", OnSuccess = "AnimateVotebox" }, null)%>
                    <%= Ajax.ActionLink("+", "VoteComment", "Votes",
                        new { id = Model.id, up = true },
                        new AjaxOptions { UpdateTargetId = "commentbox", OnSuccess = "AnimateVotebox" }, null)%>
                <% } %>
                <% else %>
                <% { %>Wijzig stem:
                    <% if (Model.HasVoted((Guid)Membership.GetUser(Context.User.Identity.Name).ProviderUserKey)
== 0) %>
                    <% { %>
                        <%= Ajax.ActionLink("-", "ChangeCommentVote", "Votes",
                            new { id = Model.id, up = false },
                            new AjaxOptions { UpdateTargetId = "commentbox", OnSuccess = "AnimateVotebox" }, null)%>
                        <p style="color:gray; font-size:20;"">+</p>
                    <% } %>
                    <% else %>
                    <% { %>
                        <p style="color:gray; font-size:20;"">-</p>
                        <%= Ajax.ActionLink("+", "ChangeCommentVote", "Votes",
                            new { id = Model.id, up = true },
                            new AjaxOptions { UpdateTargetId = "commentbox", OnSuccess = "AnimateVotebox" }, null)%>
                    <% } %>
                <% } %>

                <% } %>
            <br />
        <% } %>
        <% else  %>
        <% { %>
            <div class="display-label">Nog geen stemmen</div><br />
            <% if (canPost)
                   { %>

                    Stem: <%= Ajax.ActionLink("-", "VoteComment", "Votes",
                        new { id = Model.id, up = false },
                        new AjaxOptions { UpdateTargetId = "commentbox", OnSuccess = "AnimateVotebox" }, null)%>
                    <%= Ajax.ActionLink("+", "VoteComment", "Votes",
                        new { id = Model.id, up = true },
                        new AjaxOptions { UpdateTargetId = "commentbox", OnSuccess = "AnimateVotebox" }, null)%>
                <% } %>
        <% } %>
        <% if (HttpContext.Current.User.IsInRole("Moderator") || HttpContext.Current.User.IsInRole("Administrator"))%>
        <% { %>
            <%: Html.ActionLink("Geef probatie...", "ProbateUser", "Mod", new { comment = Model.id }, null) %>
            <%: Html.ActionLink("Verwijder...", "BanUser", "Mod", new { comment = Model.id }, null) %>
        <% } %>

        </div>

不知道这是否重要,但usercontrol加载在一个视图中,该视图链接到与上面不同的控制器。ActionLink工作正常,并在VotesController上触发操作。

我没有看到您的ajax调用,但是从第一个代码块下的小片段中,我假设您正在使用jQuery。在添加cache:false标志之前,我一直认为IE显示ajax回调的更改存在问题。我想如果这不是问题所在,那么它是否会出现在所有浏览器中?也可以显示您的ajax调用。

要调用部分更新并调用控制器操作,我使用jQuery如下

 $.getJSON(urlModeli, null, function (data) {
/*Do something with the data*/
}
然后更新内容


我确实对IE显示新内容有问题,因为我在包含我正在更新的数据的选项卡上有缓存:true,所以浏览器只是缓存了旧值,而没有显示新值,除非在刷新时

据我所知,不需要单独调用,actionlink应该会处理这个问题。这在MVC教程中也是以同样的方式实现的。我之所以说你应该显示你的ajax调用,是因为我不相信页面在没有某种javascript的情况下只会刷新部分视图。但我可能离基地很远;下面是一个示例ajax调用,我在提交时用于刷新自己项目中的部分视图。$。ajax{type:POST,url:url,data:dataString,cache:false,success:function msg{$savedformparent.fadeOutfunction{$this.htmlmsg.fadeIn;};};我认为MVC框架解决了这个问题。不管怎样,没有一个示例应用程序需要它来执行部分更新…哦,问题出现在每个浏览器中;不只是我。
 $.getJSON(urlModeli, null, function (data) {
/*Do something with the data*/
}