如何使用查询字符串参数初始化视图模型
目前,我没有使用任何类型的 MVVM 框架。因此,在导航页面上获取查询字符串参数值很简单。我的场景是一种常见的场景,我将实体的主键从“母版页”传递到“详细信息页”。
现在,我正在尝试权衡使用 MVVM 方法的好处,这是一个很好的例子,说明简单操作在 MVVM 这样的框架中可能会变得复杂。可能我一直在错误的地方寻找,但无法在网上轻松找到这方面的示例有点令人沮丧。
谢谢!
Currently, I'm not using any sort of MVVM framework. Therefore, it is simple to fetch the query-string paremeter value on a navigated page. My scenario is a common one, I'm passing the primary key of an entity from the "Master Page" to the "Detail Page".
Right now, I'm trying to weigh the benefits of using an MVVM approach and this is a good example of the simple operations that can become convoluted in a framework like MVVM. It could be that I've been looking in the wrong places, but it is a little frustrating not being able to readily find examples of this online.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不会通过在视图中插入一些代码来将查询字符串传递给 ViewModel(也许使用工厂模式)来破坏 MVVM 模式。
您应该使用这些模式来帮助您,并根据常识使用它们,有时它们会使事情变得过于复杂,并在可扩展性/可维护性方面适得其反。
You are not breaking the MVVM pattern by inserting some code in the view to pass the querystring to the ViewModel (perhaps use a factory pattern).
You should use these patterns to assist you, and use them with common sense, sometimes they will overcomplicate things and backfire on extensibility/maintainability.