C# 有没有使用POST而不是GET的MVC寻呼机?

C# 有没有使用POST而不是GET的MVC寻呼机?,c#,asp.net-mvc,pagination,C#,Asp.net Mvc,Pagination,这是我的问题。我有一个SearchViewModel,它有大量的搜索条件,这些值根本不适合URL。我目前正在使用Troy Goode的Html.PagedListPager,但它的设计目的是使用Url.Action()发送Url中的参数。这里有一个例子。我不认为客户端过滤是一种选择,因为我会有很多记录 @Html.PagedListPager( (IPagedList)@Model.SearchResults, page => Url.Action(&qu

这是我的问题。我有一个
SearchViewModel
,它有大量的搜索条件,这些值根本不适合URL。我目前正在使用Troy Goode的Html.PagedListPager,但它的设计目的是使用
Url.Action()
发送Url中的参数。这里有一个例子。我不认为客户端过滤是一种选择,因为我会有很多记录

 @Html.PagedListPager(
        (IPagedList)@Model.SearchResults,
        page => Url.Action("Results", 
            new {
                YearBuiltFrom = Model.YearBuiltFrom,
            }
                ))
}
如果只有一个或两个简单参数,这是一个很好的解决方案

SearchViewModel
公共类SearchViewModel
{
公共int?第{get;set;}页
公共整数?大小{get;set;}
[IgnoreDataMember]
公共IPagedList搜索结果{get;set;}
公共字符串[]位置{get;set;}
[IgnoreDataMember]
公共多选列表位置选项{get;set;}
公共字符串[]ZipCodes{get;set;}
[IgnoreDataMember]
公共多选列表ZipCodeOptions{get;set;}
[显示(Name=“建成年份”)]
public int?YearBuiltFrom{get;set;}
[显示(Name=“建成年份”)]
public int?YearBuiltTo{get;set;}
公共int?SqftFrom{get;set;}
公共int?SqftTo{get;set;}
公共字符串卧室{get;set;}
公共字符串浴室{get;set;}
[数据类型(DataType.Date)]
公共日期时间?SalesFrom{get;set;}
[数据类型(DataType.Date)]
公共日期时间?SalesTo{get;set;}
public int?SaleAmountFrom{get;set;}
public int?SaleAmountTo{get;set;}
公共int?LandAreaFrom{get;set;}
公共int?LandAreaTo{get;set;}
公共字符串[]海滨{get;set;}
[IgnoreDataMember]
公共多选列表选项{get;set;}
//TODO:实现LandAreaType作为搜索参数
//公共字符串LandAreaType{get;set;}
公共布尔值?是空的{get;set;}
公共字符串[]PropertyFeatures{get;set;}
[IgnoreDataMember]
公共MultiSelectList PropertyFeatureOptions{get;set;}
}

我不熟悉这样的控件。我认为最简单的方法是使用javascript劫持对寻呼机锚的点击,并通过取消锚引起的默认重定向来动态构建POST请求。要生成此POST请求,您可以动态地将当前页面值设置到搜索表单的隐藏字段中,并触发此表单的提交,以便表单再次执行搜索,但页面参数已更改

让我们举一个例子:

<!-- Search form containing all the search criteria fields including the current page number
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "searchForm" }))
{
    @Html.EditorFor(x => x.SearchCriteria)
    <button type="submit">Search</button>
}

<!-- Here will be displayed the results
<div id="results">
    @Html.DisplayFor(x => x.SearchResults)
</div>

你知道我在哪里可以看到样品吗?这是否需要将模型序列化为隐藏控件?不,不需要序列化任何内容。模型已在相应输入字段下的搜索表单中。我已经更新了我的答案,以提供一些指导。@MVCylon如果您使用的是最新版本,您可以使用$(“.PagedList pager a”)选择由PageList插件生成的锚链接,并且您可以通过此获得页码。href.split('=')[1]我将寻呼机的
页面
大小
作为我的模型的一部分。因此,在呈现“我的视图”时,将创建ID为
page
size
的字段。有没有办法将其作为设计的一部分加以利用?PS,这很有效!谢谢你们两个,只是考虑一下。在发布帖子时,您的值对用户隐藏,这使得url非常漂亮。但是,如果用户想要共享搜索结果或将搜索结果加入书签,他们将无法这样做。看起来你有一个相当密集的搜索。要共享或保存结果,他们必须告诉共享结果的人他们是如何找到结果的,这需要告诉他们他们为上面列出的每个标准项输入的所有值。
<!-- Search form containing all the search criteria fields including the current page number
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "searchForm" }))
{
    @Html.EditorFor(x => x.SearchCriteria)
    <button type="submit">Search</button>
}

<!-- Here will be displayed the results
<div id="results">
    @Html.DisplayFor(x => x.SearchResults)
</div>
$(function() {
    $('#results a').click(function() {
        // get the url of the page link
        var url = this.href;

        var page = ... extract the page parameter from the page link

        // update a hidden field inside the search form with this value
        $('#page').val(page);

        // trigger the search
        $('#searchForm').submit();

        // stop the link from navigating to the url it is pointing to
        return false;
    });
});