Use mvvm mode in ASP. net mvc Framework

Source: Internet
Author: User

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...

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.