简体   繁体   English

如何使用jQuery插件在asp.net中进行分页和搜索

[英]How to do paging and search in asp.net with jquery plugin

I have created a paging grid in asp.net with this jquery plugin(https://github.com/gbirke/jquery_pagination),that work fine.But I do not kown how to do search. 我已经使用这个jquery插件(https://github.com/gbirke/jquery_pagination)在asp.net中创建了一个分页网格,它可以正常工作。但是我不知道如何进行搜索。 I am a newbie.Thank you very much! 我是新手。非常感谢!

Let's ignore jQuery for now and assume that you'd implement search entirely in .NET, presumaly in response to a GET request with a querystring parameter called " q ". 现在让我们忽略jQuery,并假设您完全是在.NET中实现搜索,这是为了响应带有名为“ q ”的querystring参数的GET请求。

How you actually perform the search isn't relevant: I assume you have some kind of database object or Lucene index searcher that provides you with the result, then it's just a matter of paging the results of that data with optionally provided paging querystring parameters (usually called start and count ) respectively. 您实际执行搜索的方式与您无关:我假设您有某种数据库对象或Lucene索引搜索器为您提供结果,然后仅需使用提供的分页查询字符串参数分页该数据的结果即可(通常分别称为startcount )。

eg (in MVC parlance) 例如(用MVC的话)

public ActionResult Search(String q, Int32? start, Int32? count) {

    // example using L2S or EF
    var results = from d in _db.Documents
                  where d.Content.Contains("q")
                  select d;
    if( start != null ) results = results.Skip( start.Value );
    results = results.Take( count != null ? count.Value : 25 );

    return View( results );
}

Now then, when you get jQuery involved I assume you want to do the search asynchronously. 现在,当您涉及jQuery时,我假设您想异步进行搜索。 Then it's just a matter of re-implementing the server-side Search action, but return JSON, XML, or a raw HTML fragment instead of an entire view document. 然后,只需重新实现服务器端的Search操作即可,但是返回JSON,XML或原始HTML片段,而不是整个视图文档。

Presumably you'd execute an event-handler for the keypress event of a Textbox (detect the Enter/Return key), fire off the Ajax request to the Search controller action, then convert the response into HTML (if it isn't already) then insert it into your result table. 假定您将为文本框的keypress事件执行一个事件处理程序(检测Enter / Return键),将Ajax请求触发到Search控制器操作,然后将响应转换为HTML(如果尚未响应)然后将其插入结果表。 Simples. 简单。

Further technical details are omitted for various reasons. 由于各种原因,省略了进一步的技术细节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM