For Asp.net MVC developers or enthusiasts, you may not know much about the mvvm mode. Originally, this mode was developed for WPF and Silverlight.
About a year ago, when I was infatuated with Silverlight, I learned mvvm for a while. I didn't expect it to be used in MVC now.
I have read two previous articles.ArticleThis section describes mvvm. I hope it will be helpful to those who do not know mvvm. I have never used it for a long time.
Http://www.cnblogs.com/n-pei/archive/2010/08/10/1796173.html
Http://www.cnblogs.com/n-pei/archive/2010/08/02/1790671.html
At the end of last month, I was preparing to write the mvvm application under the MVC framework. However, it was a bit busy recently and complicated, so it was delayed for such a long time.
The most recent powerful knockoutjs is implemented in the mvvm mode. Official Website:
The author shares the use of this framework on mix11, video address: http://channel9.msdn.com/Events/MIX/MIX11/FRM08
Why the mvvm mode is used? In order to avoid the need to constantly capture events, we use object-oriented JavaScript and data binding. Knockoutjs is also compatible with various browsers.
The implementation principles of knockoutjs are as follows:
Each page has a viewmodel, which is the link between the server and the client. The data is stored in viewmodel, and then the data is displayed in HTML through data binding. This is very suitable for asynchronous data transmission systems. Because Asp.net MVC supports Ajax better.
It explains how to use knockoutjs. First, a viewmode is required on the page to store all the data and interactive data. If you want knockoutjs to take effect, you need to use the last line inCode.
Knockoutjs and jquery are well integrated. You can use jquery's template to display complex business data. The HTML element in contains the data-bind attribute, indicating that Ko's data binding is used, that is, the mvvm mode.
The data source in Asp.net MVC can be set to Ajax. Action transfers JSON data to viewmodel, and then uses kojs to bind data to the page. A good solution.
Next I will put some complete examples. To be continued...