12

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

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

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

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? Did we miss something?

Nathan Arthur
  • 8,287
  • 7
  • 55
  • 80
Saeed Neamati
  • 35,341
  • 41
  • 136
  • 188
  • 2
    You'll be moving all of the rendering from the server to the client. It's best to use a mix of both. Use angular for the dynamic content. – Oliver Sep 14 '13 at 08:53
  • 1
    That's exactly what we intend to do @Oliver. Performance and client limitations are not important to us in this phase. We only want to make sure that we don't lose anything. – Saeed Neamati Sep 14 '13 at 09:04
  • 1
    Client side generated code is not SEO friendly, but maybe there are some workarounds. – Chandermani Sep 14 '13 at 09:05
  • 2
    @Chandermani, if it's a web-application, SEO is less relevant :) – Moo-Juice Sep 14 '13 at 09:10

1 Answers1

4

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.

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.

Moo-Juice
  • 38,257
  • 10
  • 78
  • 128
  • 1
    Nice tip @MooJuice. We'll consider that. While we can use security post-check to prevent attacks like `form-spoofing`, it's definitely better to do a pre-check and never show that content in the first place. – Saeed Neamati Sep 14 '13 at 09:31
  • 2
    @MooJuice is totally right, but consider if your client side part of your application has no dependency to .net, you have your pure presentation layer with just html, css and javascript. so you can use it anywhere that you want. i think this is the best part of MooJuice answer that "shift the dynamic parts to the client if the rendering and logic does not require the server to do so" – Mehdi Emrani Sep 14 '13 at 09:52