ASP. net MVC2 programming model, found that there is a very strange use of this, has never been seen before, after two hours of reading the information to find finally come to the conclusion, I 'd like to share with you (I hope you can correct me if I have an incomplete understanding)
Public static string scheduleentries (this htmlhelper helper ,...)
The question I found on a foreign forum is:
The way it works for MVC is thatHtmlIn the view is a property of htmlhelper type on the viewpage class.
I have probably understood it, which means "using HTML in the view as an htmlhelper type attribute". Here, the HTML is not quite clear, I guess it only refers to the current object, that is, taking the current object as a parameter of htmlhelper. I can only understand this sentence.
Later I saw a paging control written by MVC, which also has the same syntax:
Public static ipagedlist <t> topagedlist <t> (this ienumerable <t> source, int pageindex, int pagesize, int totalcount) {return New pagedlist <t> (source, pageindex, pagesize, totalcount );}
Then I checked how to call this method and found that this method can be called as long as it inherits the ienumerable <t> interface, and the first parameter is hidden, this makes it clearer. Here, the topagedlist <t> (...) The method is added to the class of the inherited interface ienumerable <t>. The parameter with this in this method is automatically the current object with this method by default, by understanding this, We can boldly use the methods.
Private ilist <product> allproducts = new list <product> (); ipagedlist <product> productlist this. allproducts. topagedlist (currentpageindex, defaultpagesize)
The above two rowsCodeIt is an example of how to call a method with the this keyword, hoping to help you and help you understand it. If something is wrong, you are welcome to correct it.