开发者

Are the views/models of knockoutjs or similar libraries supposed to replace asp.net mvc views/models? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing开发者_JS百科 this post.

Closed 9 years ago.

Improve this question

After looking at knockoutjs, it looks like you define your view and model directly in your pages. Can your cshtml files for example share asp.net mvc views and knockoutjs views. It would seem that if your application is not javascript intensive, there is no need to use knockoutjs or something similar. Am I looking at this the wrong way? Does the knockoutjs framework replace your asp.net mvc frameworks view/models?


Knockoutjs is the client side MVVM framework. It's general purpose is to get rid of directly using those "onclick", "onchange", "onblur" event handlers and act with the UI in the way MVVM pattern defines it - through model. From the Knockoutjs.com:

By encapsulating data and behavior into a view model, you get a clean, extensible foundation on which to build sophisticated UIs without getting lost in a tangle of event handlers and manual DOM updates.

I agree with you that if your client side has got just trivial forms to just fill in and submit to server, using knockoutjs may be design overhead. But if there're calculations, UI updates, dependent inputs that should act synchronously with each other's selected value, knockoutjs gives the more clean way to achieve desired results on UI.

But these all are client side matters. They are not meant to replace models on server side. You need models on server side to perform repository operations, business validations and cases. Good server never relies on anything on client - it is the independent actor that does all that stuff that application requires. As knockoutjs is library to make you act with models on client side, in asp.net mvc viewModels are defined on server to ease the server specific operations. And technically, for the current version of asp.net mvc, you would need view models to generate the knockoutjs ones. So if you need to write the server side for your web, you will need use separate models on it. By design they may be like the knockoutjs ones, but they are not replacable by each other.

And for views - comparing asp.net mvc views and knockoutjs ones is wrong. knockoutjs views are just the concrete implementations of the general "view" that asp.net mvc defines. asp.net mvc does not define anything specific for "view", it's generally what the user receives on his browser after some interaction with server. And yes, if you use knockoutjs, then your generated views will contain knockoutjs specific markup, of course.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜