标准的方式来坚持在ASP.NET MVC的请求之间的数据 [英] Standard way to persist data between requests in ASP.NET-MVC

查看:129
本文介绍了标准的方式来坚持在ASP.NET MVC的请求之间的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是坚持请求之间数据的最标准或最佳方式?

What is the most standard or best way to persist data between requests?

我应该使用Cookie或会话变量?我感兴趣的是保持数据,如排序顺序,排序列和页面数(paginiation)。

Should I use cookies or session variables? I'm interested in keeping data like sort order, sort column, and page number (for paginiation).

我从web表单的背景因此通常这种类型的事情对我来说在我使用的控件的视图状态的自动处理来了。

I'm coming from a webforms background so normally this type of thing was automatically handled for me in the viewstate of the controls I was using.

更新

我喜欢的查询字符串的想法,搜索和更有意义的网址;然而,我工作的一个索引/表视图,其中包括与标题中的观点,和控制选项,如为的DDL筛选和呈现数据表的局部视图。

I like the querystring idea, for searching and more meaningful URLs; however, I'm working on an "index/list" view, which consists of a View with header, and "control" options, like DDLs for filtering and a partial view that renders the table of data.

中的DDL使用 $。负载()来调用控制器,它返回局部视图上一个ActionResult,有传递参数的查询字符串,但由于这些都是AJAX请求用户浏览器的主页URL未更新。

The DDLs use a $.load() to call an ActionResult on the controller, which returns the partial view, passing parameters there in the querystring, but since these are ajax requests the main page url of the user's browser does not get updated.

有没有最佳实践采取查询字符串关闭主网页的网址,并使用他们的Ajax请求其他ActionResults?

Is there a best-practice for taking querystrings off the main-page URL and using them in ajax requests to other ActionResults?

推荐答案

如果你想让它生存只能通过一个请求/重定向TempData的是你的朋友。

If you want it to survive only through one request/redirect TempData is your friend.

不过,对于像你的分页,网址是最好的方法,单独共享链接的能力。

However, for things like your pagination, URL is the best method, for the ability to share links alone.

这篇关于标准的方式来坚持在ASP.NET MVC的请求之间的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆