문제

We are discussing with the team different options of web application building using ASP.NET MVC. One of the options is to utilize MVVM everywhere on the rendered views (i.e. knockoutjs). Approach looks very powerful, however development effort to be considered.

I would like others to advise based on their experience (or point to some resource) some rough "industry standard" development time comparison. For example "using MVVM requires on average N times more/less effort for an average ASP.NET web app".

도움이 되었습니까?

해결책

I find knockoutjs very very quick to develop with. However there are a couple of things I've found make it lots quicker.

First thing, is to use coffeescript rather than javascript. ( using web workbench, which if you end up using, also switch to using SASS for css). However, there is no intellisense or anything for that.... though personally I don't that to be an issue. However coffeescript is a LOT more concise than javascript and marries up with knockout really nicely.

Next thing is the transition of data from C# to json to knockout.

typically here, in your controller, you get the data from the database (using your fav ORM), project it to a C# viewmodel, and pass it to a view ( Razor ) which then uses it and converts it to json maps it to a knockout viewmodel.

If you move all of that into your Razor view ( basically your controller passes parameters to the view ). Then you query the database and make your C# view model in your Razor view. Then this makes development a lot faster as you can basically just edit view, refresh webpage, edit, refresh ( no compile step ).

While this sounds a bit confusing written down, the reality of actually doing this is REALLY simple, and with tiny amounts of code you can build some pretty feature rich pages really quickly.

depending on what you are doing, I'd say knockout based solutions tend to be 1->10 times faster. However there will be isolated cases where a particular control in asp.net make a certain thing slightly easier, however, replicating that behavior in knockout is often not that much more work, and more importantly it's way easier to customize things to be exactly what you want.

다른 팁

Our group finally decided to discard knockout.js at this moment.

The problem of knockout.js is that there will be no good intellisense when writing the code. This makes the development error-prone and time-consuming, compared with the ViewModels in MVC.

Especially when there is need to do online-form submission, we still like to take advantage of the DataAnnotation attributes which can be set on the view models. That practice still save us a lot of time in server-side and client-side validation.

But I would say knockout.js has its benefit because more client-side programming does improve the user experience. If less postback means a lot, please consider knockout. Especially when there are a lot of things to be changed on the client side on one page. Otherwise, I would simply use ajax calls and update the page content using jQuery on the success: clause.

There is at least one future project that I want to approach with extensive knockout. It will be necessary knowledge after all. And it is not very difficult. Just follow the nice examples on the website.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top