从剃刀(asp.net),以角JS迁移作为模板引擎 [英] Migration from Razor (asp.net) to Angular JS as a template engine

查看:122
本文介绍了从剃刀(asp.net),以角JS迁移作为模板引擎的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用ASP.NET剃刀,我们大量使用剃刀生成HTML,包括部分意见的布局,做类似的东西。

We were using ASP.NET Razor, and we heavily used Razor to generate HTML, include partial views in layouts, and doing stuff like that.

然而,现在是角出健壮,我们要尽可能多,我们可以使用它。

However, now that Angular is out and robust, we want to use it as much as we can.

一个老乡的同事建议,理论上应该是可能的,我们完全有角JS更换剃须刀,我们搜查一下,似乎是可行的。

A fellow colleague suggested that theoretically it should be possible that we completely replace Razor with Angular JS, and we searched about it, and it seems viable.

例如,我们可以替换 Html.Partial ngInclude ,我们可以更换 RenderBody()< NG-视图> ,我们可以用更换循环NG-重复等。

For example, we can replace Html.Partial with ngInclude, we can replace RenderBody() with <ng-view>, we can replace loops with ng-repeat, etc.

有没有把剃刀放在一边,只与角工作的陷阱?难道我们错过了什么?

Is there any pitfall for putting Razor aside and working only with Angular? Do we miss something?

推荐答案

我什至不知道你在这里有一个问题。两款发动机都做同样的事情本质的区别在于角JS发生在客户端和剃刀发生在服务器上。通过各种手段,动态部分转移到客户机,如果渲染和逻辑不需要服务器这样做。

I am not even sure you have an issue here. Both engines do the same thing essentially, the difference being that Angular JS happens on the client and Razor happens on the server. By all means, shift the dynamic parts to the client if the rendering and logic does not require the server to do so.

如果我是你,我还是会用剃刀文件来生成最终的HTML。您可能会发现在未来的时间非常有用时,必须在服务器上生成的东西。也许你可能最终提供基于用户的权限是完全不同的控制。这是重要的,因为如果安全敏感渲染在客户端上出现,它可以潜在地通过某人规避。但是,如果该code的从未到达的,因为服务器生成它,你在一个更好的地方。

If I were you I'd still use Razor files to generate the final html. You might find it useful in the future for those times when something must be generated on the server. Perhaps you could end up serving an entirely different control based on user-permissions. This is important because if security-sensitive rendering is occurring on the client, it can potentially be circumvented by someone. However if that code never arrives because the server generated it, you're in a better place.

这篇关于从剃刀(asp.net),以角JS迁移作为模板引擎的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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