MVC页面刷新错误 - Html.DropDownListFor选择对显示的项目没有影响

时间:2014-03-12 23:54:39

标签: jquery asp.net-mvc html.dropdownlistfor

我有以下jQuery函数,该函数根据第二个代码块中显示的典型MVC cshtml中的DropDown选择进行AJAX调用以显示数据。

$(document).ready(function() {
    $("#genericDropDown").on("change", function () {
        var text = $("#genericDropDown option:selected").text();
        var options = {
            url: '/pet/index/' + text,
            type: 'GET',
            cache: false
        };

        var jqXHR = $.ajax(options);
    });
});

这是cshtml。

 @foreach (var item in Model)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Type)
            </td>
        </tr>

        etc

由于选择了全部内容,页面会以许多项目开始。当我在DropDown中进行选择时,我可以在小提琴手中看到它被正常拾取,并且在典型情况下,只从数据库中选择一个项目来刷新页面。这有效。当我在cshtml中设置断点时,我可以看到foreach循环仅按预期迭代一次。但是,刷新页面后,所有项目仍然存在,而不是我使用DropDown选择的项目。这就是我在jQuery中将缓存设置为false的原因,我也尝试了

[OutputCache(NoStore = true, Duration = 0, VaryByParam = "None")]

在控制器操作上,认为缓存导致了这种情况。但是,仍然会显示所有项目。打败了我。

请帮忙。

0 个答案:

没有答案