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

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.

Related

Silverlight/RIA Services and ASP .NET MVC/WebAPI

I did some research around but I have some doubts still about following topic...
I have Silverlight/RIA Services project that needs to have ASP.NET MVC look as well as WebAPI for some different clients.
So my question is following
Can we use somehow RIA Services with ASP.NET MVC 5?
And if not what is a painless way to represent all existing logic in ASP.NET MVC?
Thank you!
Ria services have nothing to do with look and feel.
A Silverlight app or a non plugin, which uses RIA services can be hosted in a web page created using ASP.Net.
Can we use somehow RIA Services with ASP.NET MVC 5?
Yes.
RIA services which could be used by an asp.net backend would not gain the benefit of RIA services because changes made in the backend end are not generated forward to an application such as a Silverlight plugin. It just becomes another way of accessing data.

Angular JS with 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

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

Using MVC.NET 5 with Entity Framework for Developing a REST API

I am considering using MVC.NET 5 with Entity Framework for the development of a REST API to serve up data for consumption by a few Websites. Is there any compelling reason to wait for MVC.NET 6 or is there a best practice/more common framework for developing REST APIs. The reason I am focused to MVC is so I can enter/edit data via forms that reflect my database to more easily manage my REST data, but I am open to other options if there are more common pursuits.
My front end development is heavily focused towards HTML5 and a few JS libraries such as Angular and Backbone due to the design patterns.
My recommendation is to built a stand alone Web API without mixing it with MVC 5, if you want to do it the right way use OWIN middle ware and add the components needed to build the API.
For the front end and if you are going to build SPA, start new empty project which will hold only your SPA, and this project will talk to your RESTful API.
For sure you need to allow CORS on the back-end API so it will accept calls coming from your SPA.
You can read more about how you structure this on this post. http://bitoftech.net/2014/06/09/angularjs-token-authentication-using-asp-net-web-api-2-owin-asp-net-identity/

asp.net mvc3 - calling controller actions from external app

I have an asp.net mvc3 application built with RavenDB and I want to be able to access the data via an external HTML5 mobile app. I'm thinking of exposing methods via WCF or via MVC controller action methods? Which option is best?
Ok, I have faced similar situation a while ago. This the way I have handled it, I have directly exposed Controller urls to the mobile application clients. Bascially it will help you in reducing the burden of maintaining two code bases and helps you to reuse existing functionality. Even if you go with WCF you need to expose with REST to make HTML5 client developer life easy.
This is the why microsoft released ASP.NET MVC 4 Web Apis to avoid confusion among developers which way to go in these scenarios. So that your services are device agnostic and easily testable.
Since you've already built the app in MVC3, I'd recommend a JsonResult action on an MVC Controller: http://www.asp.net/ajaxlibrary/jquery_json_data_from_controller.ashx

Resources