开发者

Asp.Net MVC 2: What's the standard way to keep selected values in forms?

开发者 https://www.devze.com 2022-12-24 04:36 出处:网络
Say you have a few DropDownLists that filter data: Car开发者_开发百科 Make:[Ford,Chevrolet,etc]

Say you have a few DropDownLists that filter data:

Car开发者_开发百科 Make:  [Ford,Chevrolet,etc]
Car Year:  [2010, 2009, 2008, etc]
Car Model: [LT, SLT, etc]

And you make a selection and not show that DDL again. Is there any standard place to maintain previously selected values? This is for a "drill down" menu system.


You can store in in a hidden field or you could store it in the session. I prefer to keep data out of the session. I'd just stick it in a hidden field and rebuild your state each on each request.


You can use the model to do this. You'll receive the selected values from the user, then just make sure when you pass the model back into the view, it has the previously selected value.

If you're using the Html helpers to render your input controls, it should wire it up for "free".

0

精彩评论

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

关注公众号