DNN Blog

Feb 17

Posted by: Steve Fabian
2/17/2012  RssIcon

In part 5, we talk about client-side databinding, and utilizing the MVVM style of development on the client with Knockout.js.

NOTICE: This is a work in progress. The template is not complete, during the course of this series we will be enhancing and tweaking the template as we build a new DotNetNuke module using these advanced technologies. The template is being released as-is so that you can download it and follow along, or participate by helping with the development. You can certainly use the template in it’s current state to build a DotNetNuke module, however, you will have to do some things manually for now until the template is complete. If you have any question at all, do not hesitate to contact me directly

The “Let’s Build a Module” series

1. Project Introduction
2. Downloading, Installing and Using the Template
3. Output Formatting
4. Data Access with Entity Framework and a WCF Data Service
5. Client side Data Binding with Knockout.js
6. Mobile Development
7. Security
8. Testing
9. Packaging and Distribution

5. Data-Binding with Knockout.js

There’s a big push these days to javscript based libraries and frameworks, moving the processing down to the client side.  The goal is to provide users with a more responsive UI, better performance by keeping the processes that need to run on the server, on the server, and move the stuff that doesn’t need to be on the server down to the client.  This elimiates a LOT of uneccessary post-backs and server round-trips.

Tempate Update

IMPORTANT NOTE: As I’ve mentioned many times throughout this series, I am developing a Project Template that you can use to build DotNetNuke modules using the technologies being demonstrated. As the series prgresses, I will be tweaking and updating the template based on feedback from you, and through experience I’m gaining by using the template to build this series.

I recently updated the template, which you can download from http://dnntechtemplate.codeplex.com/

Updates include:

- replaced the markup loading the javascript files and css files with the DotNetNuke ClientResourceManagement services. This will optimize the scripts and stylesheets being downloaded as well as make sure resources are not downloaded multiple times (very important when you have multiple modules on a page all using Knockout.js)

- Added the datajs open source libary

KEEP THE FEEDBACK COMING!

MVVM

There are a lot of MVVM tutorials on the web, so I won’t go into too much detail, but a quick overview should help those unfamiliar.

MVVM stands for “Model-View-View Model”. In essence, it breaks down responsibilities into three components.

The “Model” represents your Business Objects.  These are objects that have one or more ‘properties’, and they represent an ‘object-view’ of your data.

The “View” represents the UI. In our module the View will be the HTML markup to format and display our business objects and other status text to the user.

Finally, the “View Model” sits between the Model and the View.  The View Model is responsible for retrieving any required data from a data store, or initializing our business objects in whatever way is neccessary., then make that data available to our View through data-binding, using a data-binding engine (in our case, Knockout.js)

Demonstration Video

The following videos show how to use the Knockout.js library, datajs library and the WCF Data Service and Entity Framework we built in Part 4 to get the data from the database to the screen.

The Video has been broken up into 2 parts (10-minute youtube limit)

Part 1 of 2–Client-Side Data-Binding with Knockout.js

 

Part 2 of 2–Client-Side Data-Binding with Knockout.js

Tags:
Categories:
Location: Blogs Parent Separator Steve Fabian

7 comment(s) so far...


Gravatar

Re: Let’s Build A Module-#5 MVVM and Data Binding with Knockout

In the last post you indicated setting up the WCF service would be in the next post. Are you still going to cover that?

By Stephan Snoek on   2/17/2012
Gravatar

Re: Let’s Build A Module-#5 MVVM and Data Binding with Knockout

@Stephan, not sure what you'e referring to. The WCF Data Service is already setup in the Project Template, there is no setup required. I did mention that later in the series when we talk about security, we'll modify the WCF Data Service to require some DNN credentials to ensure people can't just browse to the WCF DS URL bypassing our DNN security, and to provide role-based security.

If you're looking for info on setting up a WCF service for use with DNN, maybe my previous series will be of some help
gooddogs.com.dnnmax.com/Blog/tabid/97/EntryId/21/WCF-lt-gt-DNN-BLog-Series-Index.aspx

By Steve Fabian on   2/18/2012
Gravatar

Re: Let’s Build A Module-#5 MVVM and Data Binding with Knockout

Really interesting blog series. Could you provide the sample project so far for reference purposes? Since the WCF Data Service doesn't work with me, I tried to figure out it's configuration, but all I found was the svc file an de corresponding code behind. I cannot find the contract, and the binding... not entries in der web.config like system.servicemodel - section were made... Perhaps the template wasn't installed correctly/completely?

Thanks, Michael

By Michael Steffen on   2/19/2012
Gravatar

Re: Let’s Build A Module-#5 MVVM and Data Binding with Knockout

@Michael, there really is no configuration, a WCF Data Service is different from a WCF Service. The WCF *Data* Service gets it's service and data contracts from the Entity Framework model. I'll post the sample project up on the codeplex site shortly

By Steve Fabian on   2/19/2012
Gravatar

Re: Let’s Build A Module-#5 MVVM and Data Binding with Knockout

Steve, thanks a lot for this clarification. I wasn't aware of that. Since I used to access Entity Framework always directly using an EntityDataSource, utilizing a service oriented method now is new to me. I'm appealed by the simplicity of this approach.
Thanks for the insight in this topic...

By Michael Steffen on   2/20/2012
Gravatar

Re: Let’s Build A Module-#5 MVVM and Data Binding with Knockout

Just a note: I had to add two references in the view.ascx file to get it work:
1. DNNJsInclude -> Models/View.js
2. DNNJsInclude -> json2.js (I've included the file into the project)

Otherwise I get a "JSON Null or not object" error and the model-definition-function is not found.

By Michael Steffen on   2/22/2012
Gravatar

Re: Let’s Build A Module-#5 MVVM and Data Binding with Knockout

Ack! I'm simply too exited to have to wait for the next part in the series! I've not familiarized myself w/ knockout.js and can't wait to see the implementation of CUD in CRUD. Love it Steve!

By Andrew Walker on   2/22/2012
Attend A Webinar
Free Demo Site
Download DotNetNuke Professional Edition Trial
Have Someone Contact Me
Have Someone Contact Me

Like Us on Facebook Join our Network on LinkedIn Follow DNN Corporate on Twitter Follow DNN on Twitter

Advertisers

Sponsors

DotNetNuke Corporation

DotNetNuke Corp. is the steward of the DotNetNuke open source project, the most widely adopted Web Content Management Platform for building web sites and web applications on Microsoft. Organizations use DotNetNuke to quickly develop and deploy interactive and dynamic web sites, intranets, extranets and web applications. The DotNetNuke platform is available in a free Community and subscription-based Professional and Enterprise Editions with an Elite Support option. DotNetNuke Corp. also operates the DotNetNuke Store where users purchase third party apps for the platform.