1. Preface
I have been engaged in B/S development for many years.ProgramApe, once used ASP, Asp.net as the main server language. Both relatively low-level ASP and advanced Asp.net may encounter the "Data Binding" issue.
2. What is "binding "?
Broadly speaking, if the server data needs to be presented on the page and the data needs to be associated with the whole page (or a part of the page) (whether one-way or two-way ), this is data binding.
3. "value assignment" is a good solution
In the ASP era, there were no controls at the root, so the data on the server was presented, basically, it is implemented by embedding <% = xxx %> in the page (xxx can be understood as a defined variable) to change the display content, the most convenient way is to assign different values to the variable XXX.
In the Asp.net era, a large number of web form controls made development easier.CodeIt is also separated from the page in the form of codebehind. If you want a gridview or repeater to present background data, simply write gridview1.datasource = xxx; gridview1.databind. Similarly, to make a Textbox Control have content on the page, simply write textbox1.text = "Hello World.
4. Should we be satisfied with the assignment? 4.1. entanglement between interfaces and logic
"Value assignment" is almost an omnipotent solution to data binding. It is easy to understand, but people are always excited. I believe that countless web programmers have encountered the following situations: soon after the website was launched, the customer found that it was not good-looking and required to redo the interface, so the UI was pushed back. However, a large number of value assignment statements are closely related to the control naming. If the ID or name of a control changes (for example, from textbox1 to textbox2), the original textbox1.text = "Hello World" cannot be compiled successfully. In other words, the assignment method binds the interface logic too tightly to the interface, and is a tightly coupled program design. When the UI is frequently updated, the Code maintenance workload is huge, which may make programmers feel at ease.
4.2. Coming Soon-MVC
In order to separate the interface from the behavior, Asp.net finally introduced the MVC mode, that is, Asp.net MVC (which has been developed to 3.0). In the MVC mode, the data model and page view are separated into two irrelevant parts, which are decoupled in a large program. When each page (that is, view) needs data presentation, the Controller pulls a copy of data from the model and then throws it to the view. That is, the Controller acts as an intermediary (or matchmaker) and is responsible for bridging the view and model. When binding data, view only needs to care about the model introduced by the matchmaker, and then uses htmlhelper to directly process the model into the final HTML code and render it on the page, you don't have to worry about the ID or name of each control. When the MVC mode encounters the UI reconstruction requirement, as long as the model corresponding to the view does not change, the code of the controller and model does not need to be modified. You only need to change the view, code maintenance is relatively easy. Everything looks very beautiful, so for a moment, MVC set off a climax, and even appeared Asp.net MVP dead argument.
4.3. When MVC is ineffective
Asp.net MVC has two obvious shortcomings:
4.3.1Incomplete code separation
In aspx, you can still use <%... %> to write server code, and manyArticleIt is even recommended to do so (even the blog on the official website of Microsoft Daniel). In my opinion, this is a certain degree of regression, and the logic and interface are mixed together, the Code-behind in webform is better than this one.
4.3.2, Binding is only one-way
Whether it is Asp.net webform or Asp.net MVC, It is a traditional Web technology, not a RIA, and two-way binding cannot be implemented. After the model is bound to the view on the server, only HTML + CSS + JS is available in the browser. If the "Browser" client "can automatically detect the changes in the UI and synchronously reflect the changes to the model itself, instead of submitting a form every time, how nice it is!
5. "Two-way binding"
The emergence of Silverlight/WPF addresses the two shortcomings mentioned above. The new XAML format replaces the aspx/ascx format. In The XAML world, no server code is allowed. This is a complete separation of the CS code/UI interface! In addition, the new twoway binding method can automatically maintain data status synchronization between the UI and the model (that is, the user has performed operations on the interface control, the Bound Model can automatically change. In turn, the model data changes, and the display of controls on the UI is automatically updated)
5.1. You jump, I jump!
There is a classic line between "quenching thirst" and "shredded meat" in "titani": You jump, I jump! The implication of this sentence is: you are dead, and I am not living. In the programmer's words, it is "State synchronization". You must keep the same State from birth to death. How appropriate is bidirectional binding! When the value of the model attribute of the data source changes, the interface will automatically change the response (update the rendering of some controls). Similarly, if you modify the control value on the interface, the corresponding properties of the model will also change. Seriously suspect that two-way binding is inspired by this classic movie: two-way binding also tells the true meaning of the SL/WPF World: data-driven UI. (According to the Buddhist saying, the UI is just an empty bag, and the internal [Flesh and Blood] is completely driven by data)
5.2, M-V-VM? Or M-VM-V?
This removes n Bytes (n> = 1024 )...
5.2 brick house rumor: Just in client, no in server!
This removes n Bytes (n> = 1024 )...
5.3. Internal Implementation Mechanism
This removes n Bytes (n> = 1024 )...
5.4. converter-adds two-way binding
This removes n Bytes (n> = 1024 )...
5.5. The ass decides the head and the train of thought determines the way out
This removes n Bytes (n> = 1024 )...
Note: give an outline first, and then return to fill in the blanks.