开发者

ASP.Net MVC - how can I easily serialize query results to a database?

I've been working on a little property search engine while I learn ASP.Net MVC. I've gotten the results from various property database tables and sorted them into a master generic property response. The search form is passed via Model Binding and works great.

Now, I'd like to add pagination. I'm returning the chunk of properties for the current page with .Skip() and .Take(), and that's working great. I have a SearchResults model that has the paged result set and various other data like nextPage and pr开发者_JAVA技巧evPage.

Except, I no longer have the original form of course to pass to /Results/2. Previously I'd have just hidden a copy of the form and done a POST each time, but it seems inelegant. I'd like to serialize the results to my MS SQL database and return a unique key for that results set - this also helps with a "Send this query to a friend!" link. Killing two birds with one stone.

Is there an easy way to take an IQueryable result set that I have, serialize it, stick it into the DB, return a unique key and then reverse the process with said key? I'm using Linq to SQL currently on a MS SQL Express install, though in production it'll be on MS SQL 2008.


This doesn't answer your question about saving queries, but it's for your need to implement paging.

Consider leveraging this ASP.NET MVC Paging solution . You add a few extension methods, a few classes, and strongly type your views with IPagedList<Product> instead of IEnumerable<Product>, for example.

Writing the pager HTML is as simple as this:

<div class="pager">
    <%= Html.Pager(Model.PageSize, Model.PageNumber, Model.TotalItemCount) %>
</div>

ASP.Net MVC - how can I easily serialize query results to a database?


(source: taiga.nl)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜