Get Agility module information in Javascript file

I have an Agility CMS MVC application, I wanted to make an Ajax call from my Javascript file. Is it possible to make an Ajax call from JS file to the controller action?

Also I wanted to know whether we can access the module information in the JS file.

Any help will be much appreciated. Thanks!



1 comment
  • Official comment

    A neat trick you can do in ASP.NET, is that you can just use your Controller Action Result for the module to simply return a JSON string containing all of your module properties you need. Then, in JavaScript you can easily consume that data. You can do this all without having to write any AJAX code. 

    If you do need to "lookup" data from a module elsewhere via JS, you can do that as well, but you'll need to set up a custom Controller Action Result for that.

    It could look like:

    ``` javascript

    var data = await getMyData('someModuleReferenceName')


    and in your C# it would look like:


    var data = Agility.Web.AgilityContentRepository<Module_SomeModule>(referenceName)

    return data; //returns the data to the client


    Comment actions Permalink

Please sign in to leave a comment.

Didn't find what you were looking for?

New post