DotNetNuke Module Development With Kendo UI and WEB API

Before starting this you should be experienced with working with DNN CMS module development and you should have some basic idea of WebApi.

Yes, we will start by creating a class library.

Here I am creating the WEB API using the simple class library, first I would like to explain that I am explaining DNN Module development with the WEB API.

Create a new class library project using Visual Studio with .NET Framework 4.0 or higher as in the following:



Add the following libraries to your project, set your output path to the root /bin folder.

  • DotNetNuke.dll
  • DotNetNuke.Web.dll
  • System.Net.Http.dll
  • System.Net.Http.formatting.dll
  • System.Web.Http.dll

Create your own controller class in your class library project.



Now I am trying to access my Microsoft SQL DB with LINQ to SQL to retrieve my table records in the service method.



In my case the code is:

  1. public class ProfilePropertyController: DnnApiController {  
  2.     TestTableDataContext db = new TestTableDataContext();  
  3.     [HttpGet]  
  4.     [AllowAnonymous]  
  5.     public IEnumerable < ProfilePropertyDefinition > ProfileProperty() {  
  6.         return db.ProfilePropertyDefinitions;  
  7.     }  
  8. }  
  9. public class RouteMapper: IServiceRouteMapper {  
  10.     public void RegisterRoutes(IMapRoute mapRouteManager) {  
  11.         mapRouteManager.MapHttpRoute("MyServicesTest""default""{controller}/{action}"new[] {  
  12.             "MyServicesTest"  
  13.         });  
  14.     }  
  15. }  
Now, it's time to check your service, using POSTMAN or Fiddler.

This is my endpoint, you will get a different one based on your project and controller Name.

Desktop Modules

If your service is working then you will get a response in JSON format like this:

 


That's it! The service was created.

It's time to consume the service in the DNN Module.

To install the DNN module template in Visual Studio, please go through this:

DotNetNuke Explained: Basic Module Development

Create a new empty DNN module using christoc's template in Visual Studio as in the following:



Open the view.ascx page.

Now I am trying to bind the HTTP get response in my Kendo Grid as in the following:

  1. <link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.408/styles/kendo.common.min.css">  
  2.     <link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.408/styles/kendo.rtl.min.css">  
  3.         <link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.408/styles/kendo.default.min.css">  
  4.             <link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.408/styles/kendo.dataviz.min.css">  
  5.                 <link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.408/styles/kendo.dataviz.default.min.css">  
  6.                     <link rel="stylesheet" href="http://cdn.kendostatic.com/2015.1.408/styles/kendo.mobile.all.min.css">  
  7.                         <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>  
  8.                         <script src="http://cdn.kendostatic.com/2015.1.408/js/kendo.all.min.js"></script>  
  9.                         <script>  
  10. $(document).ready(function () {  
  11. var carsDataSource = new kendo.data.DataSource(  
  12. {  
  13. transport: {  
  14. read: {  
  15. url: "/DesktopModules/MyServicesTest/API/ProfileProperty/ProfileProperty",//this is the HttpGet service  
  16. dataType: "json",  
  17. type: "GET",  
  18. contentType: "application/json; charset=utf-8",  
  19. },  
  20. },  
  21. shema:  
  22. {  
  23. model: {  
  24. id: "PropertyDefinitionID",  
  25. field: {  
  26. PropertyCategory:  
  27. {  
  28. editable: false,  
  29. nullable: false,  
  30. type: "string"  
  31. },  
  32. PropertyName:  
  33. {  
  34. editable: false,  
  35. nullable: false,  
  36. type: "string"  
  37. },  
  38. }  
  39. }  
  40. }  
  41. });  
  42. $("#grid").kendoGrid({  
  43. dataSource: carsDataSource,  
  44. height: "500px",  
  45. pageable: {  
  46. refresh: true,  
  47. pageSizes: true,  
  48. buttonCount: 5  
  49. },  
  50. columns: [  
  51. {  
  52. field: "PropertyCategory ",  
  53. title: "Type "  
  54. },  
  55. {  
  56. field: "PropertyName",  
  57. title: "Name"  
  58. },  
  59. {  
  60. field: "ViewOrder",  
  61. title: "SortOrder",  
  62. template: "  
  63.                             <input value='#=ViewOrder#' data-bind='value:ViewOrder' type='number' data-role='numerictextbox' />",  
  64. },  
  65. {  
  66. title: "HelpText",  
  67. template:"  
  68.                             <input id='txt_help' value='' />",  
  69. },  
  70. {  
  71. title: "FieldDescription",  
  72. template: "  
  73.                             <input id='txt_description' value='' />",  
  74. },  
  75. {  
  76. title: "Activate",  
  77. width:"70px",  
  78. template:"  
  79.                             <input id='txt_activate' type='checkbox' />"  
  80. },  
  81. { command: ["edit", "destroy"] }  
  82. ],  
  83. toolbar: ["create"],  
  84. editable: "popup",  
  85. });  
  86.   
  87.       <div class="main-content">  
  88.       <div id="grid"></div>  
  89. </div>

From the preceding design I used to bind only two record properties, category and property name from my table, the rest of the column I tried to insert the Kendo TextBox and Kendo checkboxes in the grid.

Now your grid is populated. In the future I will explain how to do create, update and delete in a Kendo Grid using the Web API in DNN.

That's it, enjoy coding.

I have attached my DNN module source code and class library project for your reference.

Up Next
    Ebook Download
    View all
    Learn
    View all