如何确定视图中操作的上下文 (asp.net mvc)
我有一个包含大量链接的视图,当用户操作这些链接之一时,它会在控制器上启动过滤操作。
当视图构建自身时,我想确定哪些链接(如果有)已被操作。
我对选择感到不知所措,是否在 ViewBag、TempData 或 ViewModel 中放入一些内容,以便视图可以确定操作的上下文?
首选方式是什么?
I have a View that contains lots of links, when a user actions one of these links it initiates a filter action on the Controller.
When the View is constructing itself I want to determine which (if any) of the links have been actioned.
I'm overwhelmed with choices, put something in the ViewBag, TempData, or in my ViewModel so that the View can determine the context of the action?
What would be the preferred way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当然是ViewModel。
ViewBag 实现了与视图模型相同的功能,但以弱类型的方式实现,因此我个人从未在任何应用程序中使用它。另一方面, TempData 可以被视为一个重定向会话存储,我不认为它对您的场景有任何帮助。
ViewModel of course.
ViewBag achieves the same thing as the view model but in a weakly typed manner, so personally I never use it in any of my applications.
TempData
on the other hand could be considered as a one-redirect-session-storage which I don't see how it would be of any help for your scenario.