ASP.NET MVC - PartialView html 未通过 jQuery html() 调用更改

发布于 2024-08-26 18:28:20 字数 1940 浏览 4 评论 0原文

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

我有点困惑。想法?

搜索.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>

When I change the selection in a DropDownList, a PartialView gets updated via a GET request. When updating the PartialView via the jQuery html() function, the html returned is correct but when it displayed in the browser it is not correct. For example, certain checkboxes within the PartialView should become enabled but they remain disabled even though the html returned says they should be. When I do a view source in the browser the html never gets updated.

I'm a little perplexed. Thoughts?

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>

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

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

发布评论

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

评论(1

滥情哥ㄟ 2024-09-02 18:28:20

没关系,我已经弄清楚了。我没有正确使用控件的属性。因此,它给人一种标记没有改变的错觉。

Never mind, I figured it out. I wasn't using a property of a control correctly. So, it was giving the illusion that the markup wasn't changing.

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