0

I've been working with ASP.NET MVC for about a year now. I enjoy the ability to create SPA's especially by using the following tools:

  1. Partial views(via html.action() and renderPartial())
  2. Ajax helpers (Ajax.Actionlink() and Ajax.beginform())

My question is, Is it safe to just continue without a JavaScript frameworks or am i seriously missing out on something by not utilising a Javascript framework like Angular JS.

3 Answers 3

3

This depends a lot of the type of application you are building, but in general you don't necessarily have to choose between ASP.NET MVC and Angular, you can use both in a project. For example, if you have a page with a grid where the user will add rows and you have to calculate sums etc you could use angular on that page (and it will speed up the development process). But if you have pages with static content you can just serve an html file there using ASP.NET MVC. And you can even use both of them. For something like a blog post, you can use a static html file for the post content and then implement the comments are with angular.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Robert, thats very insightful. Are you able to offer any guidance, in terms of the best resource i can use to learn how to mix angular with .NET MVC?
It depends a lot on the type of project that you are building. I think the best way to learn how to mix them is to do a pure angular side project (for example an WEB API 2 + angular project) and then you will better understand when to use one or another. Another option is to use React.js and then React.net that will allow you to even render views on the server at first and then on the browser.
Angular + web api 2. Perfect!
3

Since ASP.NET is a server side framework, it can only go that far as AJAX insertions. Angular JS is a client side Framework, designed for SPA in mind. If you are going for a light SPA, ASP.NET will do nicely, but I think you should use the right tools for the right job. Don't hesitate to mix them in order to find the right place between server side rendering and client side dynamism.

3 Comments

Thanks for your comment Alexandre. When mixing angular was .NEt from what i understand i would then be unable to use partial views but would have to that over to the angular views. So .NEt would only handle the server side whilst angular handles the client side, is my understanding correct?
No, not exactly. You would still be able to use partial views as they are rendered directly into the response when you first load the page. Partials have two purposes: to provide a way to to reuse HTML fragments and also to make your markup cleaner and to send fragments of html as a response when necessary. In other words you can request MVC-served partials as HTML fragments, which can actually be also angular views. This solution, for example, allows you to control your views' availability based on roles. So you can serve some angular view to admins but not to regular users.
@Balázs exactly what I would have answered. In the end, HTML is HTML, you have the power to decide where and when it should be computed and rendered depending on security and Search Engine Optimization constraints.
2

You are definitely missing some things.

The purpose of frameworks such as angular is not just to handle your bootstrap tab switches or whatever to display just parts of the UI rather than everything. Sure, you can create small and simple SPAs by utilizing such logic but once you come to create real-world apps that approach will become unusable. The reasons to this are:

  • Your site will be highly unmaintainable
  • Frameworks like angular provide much more than just templating (more on that in a moment) but features such as routing, which allows on-demand content loading. That is, instead of sending the whole page to the client, much of which (s)he maybe will not even take a look at, you can load fragments of HTML on-demand, which reduces network usage. Imagine you had to download everything (posts, images, videos, chat messages etc) on Facebook and hide them until you actually want to see them.

Back to templating, this is a very powerful feature. Again, in the case of simple apps you can use custom JS code - that is, concatenate strings to create fragments of HTML and then insert them into the DOM. But even with simple apps this is a smelly thing to do. Imagine you had to write custom JS to concatenate your chat messages in an app like Facebook then insert them into the DOM. With angular2, for example, you can do something like this:

<ul>
  <li *ngFor="let msg of messages">{{msg.Sender}} said: {{msg.Content}}</li>
</ul>

This way, Angular2 will do all the parsing and DOM handling for you. That is, you write declarative markup rather than imperative logic for what you want to display.

All in all, they help you to decouple the logic from the UI so you should definitely dig into any of the popular frameworks and get a taste of their capabilities if you want to create rich apps. You will not regret it.

2 Comments

Thanks Balazs, Your response is very informative. What is a reliable resource to learn about on-demand content loading with angular, this is something i would be looking into!
Thanks! Much appreciated

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.