ASP.NET MVC 2:视图中的模型是否保持最新?
我目前正在使用 jQuery 来使视图中的内容保持最新,因为在我的表单中选择了选项。但我的模型反映了这些表单元素,因此我开始思考:是否可以在模型元素发生变化时保持模型元素最新?
I'm currently using jQuery to keep things up to date in the View as options are selected in my Form. But my Model reflects those form elements so I was starting to think: is it possible to keep the model elements up to date as they are changing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Knockout JS 是你的朋友:
http://knockoutjs.com/
编辑:它可以帮助你将模型移动到客户端这样你的 JS 代码就可以根据用户交互保持最新。从那里开始,您只需将其移回服务器端即可使用。这是另一件需要学习的事情,但在复杂的视图中,它消除了复杂性并避免了客户端和服务器之间模型管理的分离:现在一切都在客户端中。
因此,总而言之,您可能会有更多的代码,但它会更容易阅读和维护。
Knockout JS is your friend:
http://knockoutjs.com/
Edit: It helps you move your model to the client side so that your JS code can keep it up-to-date according to user interaction. From there on, you can simply move it back, ready-to-use, to the server side. It's one more thing to learn but in complex views, it removes complexity and avoids the separation of model management between client and server: Everything's now in the client.
So, all in all, you'll probably have a little more code but it will be far more easy to read and maintain.