Angular JS with MVC - asp.net-mvc

I want to know if Angular JS can be used with ASP.NET MVC architecture in any way? I have tried searching on Google, but can't figure out if Angular JS is usable in .cshtml page of ASP.NET MVC and is it the good idea to use it?

you can definitely use AngularJs with Asp.Net MVC as it is a client side framework which entirely runs in the browser. It doesn't depend on any of the Asp.Net features as such. There are lot of samples available online. Here is a channel 9 video which guides you through

From the official ASP.net pages: Hands On Lab: Build a Single Page Application (SPA) with ASP.NET Web API and Angular.js
The fact that is uses WebAPI shouldn't really matter here, as that's a detail matter of implementation. AngularJS works fine on top of either.
First hit on google...

If you looking to achieve CRUD in your application I recommend this post as a guide to follow. Even though this uses WEB API, its still a good way of getting to grips with angularjs.
Hope this helps.
CRUD with SPA, ASP.NET Web API and Angular.js

Related

Should I use asp.net Mvc with Angular 4 Cli ?

I am a beginner to angular4 wanted to integrate angular with asp.net MVC,
Should I use the only Angular to develop web Application or with MVC ?
AngularJS is a Client Side web (for browser) development framework, and it has nothing to do with the server-side stuff (eg. database related operations or managing user session).
You can use ASP.NET MVC with angular, but it's a good practice to use WEB API, because the View part from MVC will be taking care by the angular framework.
It shouldn't be a problem. You'll need to add a json api to your .net app but people do it all the time. As with everything, right tools for the right job though.

What is the use of WebAPI checkbox in ASP.NET MVC?

I am trying to create an ASP.NET MVC web application,I'm trying to understand what is the use of the check mark "WebAPI" ,I don't seem to find any different selecting or unselecting this while creating the project,can anyone throw some light?
ASP.NET Web API is a framework that makes it easy to build HTTP services that reach a broad range of clients, including browsers and mobile devices. ASP.NET Web API is an ideal platform for building RESTful applications on the .NET Framework. Web API: Guidance.
You can take knowledge from this video. Thanks

ASP.NET MVC and AngularJS authorization

I am currently at the beginning process of starting a new application and am quite new to MVC and Angular. So far i have created a custom authorize attribute using asp.net MVC, this enables me to use the [Authorize] tag. Is it possible to use with an AngularJS front-end?
Any resources that will point me in the right directions would be appreciated.
AngularJs is really good for single-page-applicaitons (SPA). So just separate your front-end and back-end layers. Use Angular to implement all the views and front-end stuff. Use ASP.NET WebAPI to expose REST API for front-end (and maybe mobile) app.
A few useful links:
Angular Routing module
ASP.NET WebAPI Bearer token authorization with AngularJs
Routing in SPA with AngularJs
The answer is YES! So you can still benefit from ASP.NET MVC features like authentication and authorization etc. and still use AngularJS on the client.
I actually had the same question and after a bit of research I discovered the following.
It's true we should embrace SPAs (single page apps) but at the same time we should not just discard mature server-side frameworks such ASP.NET MVC. You can simply have a hybrid web app or mini SPA as we also call them. These web applications use normal ASP.NET MVC routing to show views and then, once the view loads you can leave all the responsabilities to AngularJS. Miguel Castro uses the term SPA silos. Plus you can benefit from AngularJS' routing as well. Miguel Castro also explains how to use them both together to get the best of server and client side. I really suggest seeing his presentation (link below).
In that way you can still benefit from ASP.NET MVC great features like Authentication, Authorization and others but still have AngularJS run your views.
I got this answer on the following locations that you definitely should check out:
Miguel Castro: AngularJS for ASP.NET MVC Developers
PluralSight - Cooper, Eames: AngularJS for .NET Developers
StackOverflow: Mixing Angular and ASP.NET MVC/Web api?
StackOverflow: ASP.NET MVC and Angular JS tipping point

How to find the path to the REST service in ASP.NET MVC SPA

I'm playing with ASP.NET MVC SPA with Knockout, and I've noticed that the sample code generated by Visual studio hard-codes the URL for the API in the javascript code as "/api/...". Obviously this only works if the application is rooted at '/' on the web server. I would have thought there might be something built into the framework to handle this but I can't find it.
At the moment I've just put the following in my _Layout.cshtml to create a global javascript variable:
var ApplicationPath = '#HttpContext.Current.Request.ApplicationPath';
But it seems a bit kludgy and breaks the separation of concerns given that this is supposed to be a state-of-the-art design paradigm. Is there a better way to do this?
I have always used relative URLs at the past (with web forms) but it seems to me this would be a bad idea in MVC because because you can get at the same page by /myApp, /myApp/Home or /myApp/Home/Index.

ASP.Net MVC4 Web Api with Help Page of WCF possible?

I am starting to develop with Web Api MVC 4 and created the whole stack. My services are working but I wonder if it is possible to see a Help Page similar to what exists on WCF.
Does anyone know?
Thanks
Checkout the ASP.NET Web API Help Page which is available as a NuGet package:
http://blogs.msdn.com/b/yaohuang1/archive/2012/08/15/introducing-the-asp-net-web-api-help-page-preview.aspx
Not currently but this is in the MVC 4 roadmap:
http://aspnet.codeplex.com/wikipage?title=ASP.NET%20MVC%204%20RoadMap
Web API Help page generation: We want to make it easy to generate rich, web-based documentation
for your web APIs, including the resource URIs, the allowed HTTP methods, expected parameters, and
sample message payloads.

Resources