【问题标题】:ASP.NET MVC - PartialView html not changing via jQuery html() callASP.NET MVC - PartialView html 不通过 jQuery html() 调用更改
【发布时间】:2010-03-25 19:14:57
【问题描述】:

当我更改 DropDownList 中的选择时,PartialView 会通过 GET 请求进行更新。通过 jQuery html() 函数更新 PartialView 时,返回的 html 是正确的,但是当它显示在浏览器中时它是不正确的。例如,PartialView 中的某些复选框应该启用,但即使返回的 html 显示它们应该启用,它们仍保持禁用状态。当我在浏览器中查看源代码时,html 永远不会更新。

我有点困惑。想法?

Search.aspx

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

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Search
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <script type="text/javascript">
        $(document).ready(function () {
            $("#Sections").change(function () {

                var section = $("#Sections").val();
                var township = $("#Townships").val();
                var range = $("#Ranges").val();

                $.get("Search/Search?section=" + section + "&township=" + township + "&range=" + range,
                function (response) {
                    $("#cornerDiv").html(response)
                });
            });

        });
    </script>

    <h2>Search</h2>

    <%--The line below is a workaround for a VB / ASPX designer bug--%>
    <%=""%>
    <% Using Ajax.BeginForm("Search", New AjaxOptions With {.UpdateTargetId = "searchResults", .LoadingElementId = "loader"})%>        
        Township <%= Html.DropDownList("Townships")%>
        Range <%= Html.DropDownList("Ranges")%>
        Section <%= Html.DropDownList("Sections")%>

        <div id="cornerDiv">
            <% Html.RenderPartial("Corners")%>
        </div>

        <input type="submit" value="Search" />        
        <span id="loader">Searching...</span>
    <% End Using%>
    <div id="searchResults"></div> 

</asp:Content>

【问题讨论】:

    标签: jquery asp.net-mvc-2 asp.net-mvc-partialview


    【解决方案1】:

    没关系,我想通了。我没有正确使用控件的属性。所以,它给人一种标记没有改变的错觉。

    【讨论】:

    • 附带说明,ajax 调用不应更新大多数浏览器的“查看源代码”功能。 Ajax 调用通常只修改 DOM。
    • @NickLarsen:感谢您指出这一点。我多么愚蠢,没有意识到这一点。 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-06
    相关资源
    最近更新 更多