Create your own shared JS Library

Source: Internet
Author: User

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.

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.