ASP.NET MVC Razor视图与AngularJS [英] ASP.NET MVC Razor view vs AngularJS

查看:210
本文介绍了ASP.NET MVC Razor视图与AngularJS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Views中使用带有Razor语法的ASP.Net MVC.但是,在对性能增强的研究很少的情况下,我发现View Engines花了一些时间将剃刀代码编译为HTML.那么在Views中使用razor语法使用AngularJS是个好主意吗?如果这样可以提高性能,那么它的其他优点和缺点是什么?

谢谢.

解决方案

哪种路线将为您提供更好的性能取决于几个因素. zambeb关于 mvc.net 剃刀视图的答案不准确.

mvc.net视图是在首次请求时进行编译的,此后仅将数据插入到预编译的视图中.与解析和呈现角度视图相比,此操作占用的处理器少得多.

但是,角度视图是在客户端上渲染的(浏览器).如果由于某些原因服务器不足以满足您的需求,则使用 angular 构建站点会更好.

另一方面,如果两个站点都使用足够大小的服务器构建,则 mvc.net 往往会具有更快的渲染时间,因为浏览器的工作强度较低.

当然这是一个例外,如果您正在构建一个站点,而该站点将具有许多您希望通过视图而不是通过dom操纵或窗口小部件进行视图更改的ui,那么 angular 会再次获胜.

这就是为什么在使用 mvc.net 进行构建时,比 angular 进行构建更大,更复杂的视图是有意义的,而不是必须这样做.

最后,每种方法都可能被滥用并且效果不佳.每种方法还适合特定的网站风格.

这两种方法也可以结合使用.在mvc.net中,可以创建一个布局页面以将视图呈现为html片段.这意味着前端有角度的开发人员只需要担心静态视图和控制器,而mvc.net开发人员则关心服务器上的模型,动态视图和控制器.

祝你好运!

I am using ASP.Net MVC with Razor syntax in Views. But with little research on performance enhancements I have found that View Engines takes a time to compile razor code to HTML. So is it good idea to use AngularJS in Views over razor syntax? If this improves performance then what are the other pros and cons of it?

Thanks in advance.

解决方案

Which route will give you better performance is dependent on several factors. zambeb's answer regarding mvc.net razor views is not accurate.

mvc.net views are compiled the first time they are ever requested and thereafter only data is plugged into the pre-compiled view. This is a much less processor intensive operation than angular views being parsed and rendered.

However, angular views are rendered on the client (browser). If for some reason your server is insufficient for your needs your site will perform better if built with angular.

On the other hand if both sites are built with adequately sized servers an mvc.net will tend to have faster render times, because the browser has a less intensive job.

The exception to this is of course if you are building a site that will have many small ui changes that you wish to make with views instead of through dom manipulation or widgets, then again angular wins.

This is why when building with mvc.net it makes sense to build slightly larger and more complex views than angular, not that you must.

In the end each approach can be abused and under perform. Each approach also lends itself to a particular style of site.

These two approaches can also be combined. In mvc.net a layout page can be made to render views as html fragments. This means a front end angular developer only need worry about static views and controllers and the mvc.net developer concerns himself with models, dynamic views, and controllers on the server.

Good luck!

这篇关于ASP.NET MVC Razor视图与AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆