2

So I've noticed a trend lately of .net web developers using angular.js on the client side of applications and I've become more curious as I play around with angular and compare it to how I would do things in asp.net mvc.

I'll give a quick example of what really got me thinking.

I recently came across a situation at work (I work in a .net environment) where I needed to create a table bound to a collection of objects that had the ability to add and remove rows/items from the collection. I had an add button that created a new object and appended a row to the end of the table, and a remove button in each row to remove a particular object/row. Using asp.net mvc, I first found myself making an ajax call to the server for each operation, updating the server side model, and refreshing part of the page to show the result in the table. This worked but I didn't really like the idea of calling the server to update the model each time, so I tried to come up with a solution to do this on the client side. It turned out to be quite a task, as I had to generate the html on add with validation and all and the correct indexing for the model binding to work. It got worse on remove, as I ended up with a crazy string replace function to recreate the indexes on each item to satisfy the binding requirements (if an item other than the last is removed, the indexes are no longer correct). Now out of curiosity, I tried to recreate this at home in angular (which I had no experience with) and it took me all of about 10 minutes with simple functions to add and remove items from the client side model.

This is just one example, but it seems to me that I'm able to achieve the same results with far fewer calls to the server in angular because of the fact that it binds to a client side model.

So my question is, is this a distinct advantage of using a javascript mvc framework or am I somehow under utilizing the power of asp.net mvc and am I right in thinking that these operations should be done on the client and have no business requiring calls to the server?

3
  • Is this client a smart phone with limited resources?
    – JeffO
    CommentedApr 14, 2014 at 13:14
  • @JeffO Generally speaking, though I would always hope to create the best experience for any client, web or mobile.
    – aw04
    CommentedApr 14, 2014 at 14:29
  • In general, significant client-side interaction (such as maintaining rows in a table) requires client-side code. ASP.NET MVC proper is mostly about server-side interactions. Updates to the server can occur one by one, or all at once.CommentedApr 14, 2014 at 20:00

5 Answers 5

3

It seems that what you're describing is client-side data-binding, which is one small part of what AngularJS does. (It also does routing, view templating, and a ton of other stuff.)

If what you're interested in is just adding the client-side data-binding piece to your otherwise just-fine ASP.NET MVC framework, there are other options (such as knockout.js) which you should investigate before deciding what works best for you.

There is no one answer to the question of how much functionality should be client-side vs server-side.

1
  • Thanks for your answer. Since posting this question, I have gone deeper into angular and actually looked into knockout as well. The more I learn the more I feel I can benefit from the power of a client side framework and the more I understand what it brings to the table.
    – aw04
    CommentedApr 22, 2014 at 17:10
3

I have been working in Angular (with ASP.Net WebAPI for the data access layer) for a while now and had to jump back to ASP.Net MVC. One thing I noticed right away about ASP.Net MVC was the awkwardness of having to frequently switch between javascript/C# and having to mix server-side and client-side code. As much as I used to love ASP.Net MVC, Angular made me really appreciate being able to work with one language for most of a project; particularly a language that is so client-side oriented. Something as simple as displaying growl notifications from server-side actions is a pain in ASP.Net MVC, whereas in Angular it is second-nature.

I also really noticed how my views in Angular are so much cleaner and simpler, not having all kinds of javascript (ie business logic) polluting them. In ASP.Net MVC, you will almost inevitably pollute your views with business logic.

In the end, I much prefer Angular over ASP.Net MVC, and that is coming from someone who has worked almost exclusively with MS development platforms his whole career.

    1

    Its absolutely the power of angularjs, when ever there is a change in the model, it will observe it and update the view. ASP.Net is all about managing data at server side, you must be basically making ajax calls and it can be any server not only an asp.net mvc application. We are using angular in one of our projects, it absolutely increased the developer productivity. Its still evolving and its great fun....

    2
    • 1
      While your answer is correct, it doesn't really answer the question.CommentedApr 22, 2014 at 17:03
    • I think it does answer part of my question. At the very least it's relevant enough to add value.
      – aw04
      CommentedApr 22, 2014 at 17:14
    0

    Greatest benefit of using AngularJS framework (MVC) at client side is TWO WAY BINDING. Basically Asp net MVC is at server side.And you can use angularjs at client side for binding data.

      0

      In the end it depends on what you are trying to achieve. Whether it is nice user interface and sleek functionality or just basic implementation.

      In case of using AngularJS for implementation of UI, you have some basic functionality that people have already wrote about. "Two Way Binding"

      The beauty of this is you do need to do too much to manipulate data as it works like model and collection in .NET, once you modify data, they are there and you do not need to worry about updating, managing data also has simple way to update any changes without reloading whole page all the time. I believe that is the main reason why people are using it and we will do more (is simple, fast to deliver results to users and looks nice).

      hope this helps

        Start asking to get answers

        Find the answer to your question by asking.

        Ask question

        Explore related questions

        See similar questions with these tags.