I have an MVC4 application with a Model (Entity) DLL project that is used in the BusinessLogic and DataAccess layers. The MVC Controllers convert the ViewModels (bound to the Views) to the Models using some mapper extension methods and pass the Model objects to the BusinessLogic layer.
My question is: If I need some client-side features like KnockoutJS, is it good practice to create a further set of KnockoutJS ViewModels? I am concerned about maintainability and frequent changes in the ViewModels.
I would say no, knockoutJS is a client-side library and therefore shouldn’t really dictate how your server sends down data. As long as your view models contain all the relevant information required to render then that’s all you need. How the client then handles that is completely irrelevant to the server.
By creating knockoutJS specific view models your essentially coupling your server responses to your client which is not a good idea – what if down the line you changed to a different client? What if you want to support multiple clients?
I would recommend creating a client-side representation of your view model which is specific to KnockoutJS instead.