using jQuery and what is the syntax?

Please post public support tickets here. Note: for private support tickets, please send an email to support@cshtml5.com instead.
Sesztak
Posts: 172
Joined: Fri Jun 24, 2016 2:19 am

using jQuery and what is the syntax?

Postby Sesztak » Mon Oct 10, 2016 1:56 am

Dear JS-Support,

Is it possible to use jQuery with CSHTML ? What is the basic syntax to pass & get objects between CSHTML5 and jQuery ?

Waiting for your kind reply,
Br,
Péter

JS-Support @Userware
Site Admin
Posts: 1128
Joined: Tue Apr 08, 2014 3:42 pm

Re: using jQuery and what is the syntax?

Postby JS-Support @Userware » Mon Oct 10, 2016 2:39 am

Hi,

To use jQuery in a CSHTML5 project, follow these steps:

1) Copy the jQuery library file (.js) into your CSHTML5 project

2) When the application starts (for example in the "Loaded" event of "MainPage.xaml.cs"), call "await CSHTML5.Interop.LoadJavaScriptFile(...)" and pass as parameter the URI of the jQuery library file (.js). You can use either the "ms-appx:///AssemblyName/FolderName/FileName.js" syntax, or the Silverlight-style "component;" syntax.

3) Now jQuery is available to all your JavaScript calls. This means that you can use it in your calls to "CSHTML5.Interop.ExecuteJavaScript" method. For people who are new to Interop calls, here is the reference:
http://cshtml5.com/links/how-to-call-javascript.aspx
Please note that inside the "ExecuteJavaScript" method, the "$" syntax may collide with the "$0", "$1", "$2", etc. which is used to pass objects from the C# world to the JS world (see reference link above). Therefore, you may want to replace "$" with "jQuery". To do so, simply call "jQuery.noConflict()" at the beginning. You can learn more here:
https://api.jquery.com/jquery.noconflict/

Regards,
JS-Support

Sesztak
Posts: 172
Joined: Fri Jun 24, 2016 2:19 am

Re: using jQuery and what is the syntax?

Postby Sesztak » Mon Oct 10, 2016 2:45 am

Great Thanks !
br,
Péter


Return to “Technical Support”

Who is online

Users browsing this forum: No registered users and 11 guests

 

 

cron