Until last night, one months of MVC and jquery, from the practice, found that jquery code is also the same as the C # language can be refactored, multiple pages have the same method function, can be placed in a single JS file or custom JS library.
You can refer to this library file when you are using it. As a simple example, the two drop-down linkage functions described earlier, whether in MVC or editing, require several identical functions to be implemented. There is no redundancy for the JS code. So we can refactor them.
Under the Scripts directory under the MVC application, create a insus.common.utility.js library.
JS class Library, just a simple move two functions. There is a place where the #23 line code is changed to #24 line. This makes it compatible with the linkage of the drop-down lists created and edited by MVC.
Next, we can modify the update.cshtml and create.cshtml views, first look at the update.cshtml view:
We have added the # # line code, which refers to the JS library just created. Or remove the #105 to #127 line code. Look at the create.cshtml view again:
Quote the line code, the #15 changed to #16 Line, the #31 changed to #32. Remove the #37 to #57 line code.
By this change, we have achieved our original purpose.