页面标题显示两次

时间:2018-06-25 09:20:55

标签: c# ajax razor asp.net-mvc-5

我遇到一个奇怪的问题,即当我更改显示的结果数时,页面标题显示两次。

主视图 //添加@ {并加入viewbag关键字

@{
    ViewBag.Title = "Societies & Proxies";
}

@section scripts {
    <script language="javascript" type="text/javascript">
    @* DOM ready? *@
    $(function () {
        addTableStylingScripts();

        @* Pagination Async Partial Handling *@
        $(document).on("click",
            "#indexPager a",
            function() {
                if ($(this).parent().hasClass('disabled') || $(this).parent().hasClass('active'))
                    return false;
                $.ajax({
                    url: $(this).attr("href"),
                    type: 'GET',
                    cache: false,
                    success: function(result) {
                        $('#tableContainer').html(result);
                        addBootstrapTooltips("#tableContainer");
                    }
                });
                return false;
            });
        $(document).on("change",
            "#pageSizeSelector",
            function() {
                var selectedValue = $(this).val();
                $.ajax({
                    url: selectedValue,
                    type: 'GET',
                    cache: false,
                    success: function(result) {
                        $('#tableContainer').html(result);
                        addBootstrapTooltips("#tableContainer");
                    }
                });
            });

        @* Sorting Async Partial Handling *@
        $(document).on("click",
            "#tableHeader a",
            function() {
                $.ajax({
                    url: $(this).attr("href"),
                    type: 'GET',
                    cache: false,
                    success: function(result) {
                        $('#tableContainer').html(result);
                        addBootstrapTooltips("#tableContainer");
                    }
                });

                return false;
            });
    });
    </script>
}

@section additionalStyles {
    @Styles.Render("~/plugins/datatables/media/css/cssDatatables")
}

<article class="row">
    @*<h1 class="pageTitle artistHeader fw200 mb20 mt10">@ViewBag.Title</h1>*@

    <div class="col-md-12">
        <div class="panel panel-visible" id="tableContainer">
            @Html.Partial("_SocietiesList", Model)
        </div>
    </div>
</article>

局部视图

    @model SocietySearchViewModel

@{  
    var start = (Model.PagingInfo.Page * Model.PagingInfo.Take) - Model.PagingInfo.Take;
    var tableRowIndex = start;
}

<div id="pagingInformation"
     style="display: none"
     data-page="@Model.PagingInfo.Page"
     data-take="@Model.PagingInfo.Take"
     data-sortpropertyname="@Model.PagingInfo.SortPropertyName"
     data-sortascending="@Model.PagingInfo.SortAscending">
</div>

@*Panel Body*@
<div class="panel-heading createContentTitle">
    <div class="panel-title createLink">
        <a href="@Url.Action("Create", "Society", new
            {
                page = Model.PagingInfo.Page,
                take = Model.PagingInfo.Take,
                sortBy = Model.PagingInfo.SortPropertyName,
                sortAsc = Model.PagingInfo.SortAscending
            })" data-container="body" data-toggle="tooltip" title="Add Society/Proxy" id="createSocietiesLink">
            <span class="fa fa-file"></span>&nbsp; Add Society / Proxy
        </a>
    </div>
</div>
<div class="panel-body pn">
    <table class="table table-striped table-hover dataTable admin-form theme-primary societiesTable" cellspacing="0" width="100%" role="grid">
        <thead id="tableHeader">
            <tr>

                <th class="sorting text-left @Html.SortTitleItem("Name", Model.PagingInfo.SortPropertyName, Model.PagingInfo.SortAscending)">
                    <a href="@Url.Action("MaintainSocieties", "Society", new
                        {
                            page = 1,
                            take = Model.PagingInfo.Take,
                            sortBy = "Name",
                            sortAsc = Model.PagingInfo.SortPropertyName != "Name" || !Model.PagingInfo.SortAscending
                        })" data-container="body" data-toggle="tooltip" title="Sort by Society Name">Society Name</a>
                </th>

                <th class="sorting text-left hidden-xs @Html.SortTitleItem("CISACCode", Model.PagingInfo.SortPropertyName, Model.PagingInfo.SortAscending)">
                    <a href="@Url.Action("MaintainSocieties", "Society", new
                     {
                         page = 1,
                         take = Model.PagingInfo.Take,
                         sortBy = "CISACCode",
                         sortAsc = Model.PagingInfo.SortPropertyName != "CISACCode" || !Model.PagingInfo.SortAscending
                     })" data-container="body" data-toggle="tooltip" title="Sort by Society Number">CICAC Code</a>
                </th>
                <th class="sorting text-left hidden-xs @Html.SortTitleItem("ShippingTarget", Model.PagingInfo.SortPropertyName, Model.PagingInfo.SortAscending)">
                    <a href="@Url.Action("MaintainSocieties", "Society", new
                     {
                         page = 1,
                         take = Model.PagingInfo.Take,
                         sortBy = "ShippingTarget",
                         sortAsc = Model.PagingInfo.SortPropertyName != "ShippingTarget" || !Model.PagingInfo.SortAscending
                     })" data-container="body" data-toggle="tooltip" title="Sort by Shipping Target">Alternative Shipping Target</a>
                </th>
                <th class="sorting text-left hidden-xs hidden-sm text-center @Html.SortTitleItem("ProxyOrganisation", Model.PagingInfo.SortPropertyName, Model.PagingInfo.SortAscending)">
                    <a href="@Url.Action("MaintainSocieties", "Society", new
                     {
                         page = 1,
                         take = Model.PagingInfo.Take,
                         sortBy = "ProxyOrganisation",
                         sortAsc = Model.PagingInfo.SortPropertyName != "ProxyOrganisation" || !Model.PagingInfo.SortAscending
                     })" data-container="body" data-toggle="tooltip" title="Sort by Proxy Organisation">Proxy Organisation</a>
                </th>
                <th class="bg-white th-10 text-center">Action</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var t in Model.Societies)
        {
            <tr data-id="@t.ID"
                data-isdeleted="@t.IsDeleted"
                data-rowversion="@t.RowVersion"
                data-societyname="@t.SocietyName"
                data-cisaccode="@t.CISACCode"
                data-shippingtarget="@t.ShippingTarget"
                data-proxyorganisation="@t.ProxyOrganisation">

                <td>@t.SocietyName</td>
                <td class="hidden-xs">@t.CISACCode</td>
                <td class="hidden-xs">@t.ShippingTarget</td>
                <td class="hidden-xs hidden-sm text-center">
                    @if (t.ProxyOrganisation)
                    {
                    <span class="fa fa-check-square fs24 societyCheck" data-toggle="tooltip" title="This society has a proxy organisation" aria-hidden="true"></span>
                    }
                    else
                    {
                    <span class="fa fa-square fs24 societyCheck" data-toggle="tooltip" title="This society has no proxy organisation" aria-hidden="true"></span>
                    }
                </td>
                <td class="updateTableRow text-center">
                    <div class="dropdownContainer btn-group text-right">
                        <button type="button" class="btn btn-primary br2 btn-xs fs12 dropdown-toggle table-btn" id="table-actionbtn" data-toggle="dropdown" aria-expanded="false">
                            Action
                            <span class="caret ml5"></span>
                        </button>
                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                            <li>
                                <a href="#" data-container="body" data-toggle="tooltip" title="Edit Details" data-rowhover="editTableRow">Edit Details</a>
                            </li>
                        </ul>
                    </div>
                </td>
            </tr>
        tableRowIndex++;
    }
        </tbody>
    </table>

    @Html.Partial("_Pagination", Model.PagingInfo)

我有点不确定是什么引起了这个问题,因为它不在源代码中,只有当您检查显示的元素时,我才检查了代码并确保所有开始和结束标记匹配,但是我有相同的AJAX和用于相似页面的局部。因此,我发现奇怪的是,它刚好出现在此页面上。

1 个答案:

答案 0 :(得分:0)

必须添加

// AJAX?
        if (!Request.IsAjaxRequest())
        {
            return View(model);
        }
        return PartialView("_SocietiesList", model);
    }

像以前一样,在我的“发帖请求”中返回整个页面,而不是部分页面。

相关问题