开发者

Retain ViewData when editing variable length list

开发者 https://www.devze.com 2023-02-04 14:27 出处:网络
I\'m editing variable length lists and use ViewData to pass around information for filling a DropDownList. I use the method described here for editing these lists:

I'm editing variable length lists and use ViewData to pass around information for filling a DropDownList. I use the method described here for editing these lists: http://blog.stevensanderson.com/2010/01/28/editing-a-variable-length-list-aspnet-mvc-2-style/

The data for this dropdownlist c开发者_如何学JAVAomes from the database. As the ViewData is not available across requests, I currently do a new query to the database each and every time. This also happens when the ModelState is not valid and the form is redisplayed. Of course, this is less then ideal even for a light-weight query as this one.

How can I retain the information from that query across requests as long as the user is editing the page with that variable length list?


If the list is unique to a user, you can store it in Session. If it's shared amongst all users you can store it in Cache. In either case, the stored list can and will expire, so you must be prepared to re-query it.

0

精彩评论

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

关注公众号