Should I be using both AngularJS and ASP.NET MVC?


I started learning AngularJS and ASP.NET MVC, but am not sure why
to use them both together in the same project?



Aren't they both MVC frameworks? Should I be using them both in the
same application? Isn't it one or the other?

I am trying to use ngRoute to link to an html and/or cshtml
document in my ASP.NET MVC 5 project:



/Views/Home/index.cshtml:



<ul class="pager">
<li><a href="#/route1">Route 1</a></li>
<li><a href="#/route2">Route 2</a></li>
</ul>
<div ng-view></div>


I've tried so many ways to type the file-path that I'm convinced
it's the way that ASP.NET MVC handles the routing and views, href="http://stackoverflow.com/questions/26873840/running-a-copy-of-a-cshtml-file-gives-a-404/26874191#26874191">something
that I've recently learned here. Here's my latest attempt at the
templateUrl element:



/Scripts/app/app.js:



var app = angular.module('app', ['ngRoute']);

app.config(['$routeProvider',
function ($routeProvider) {
$routeProvider.
when('/route1', {
templateUrl: '/Views/Modules/page1.html',
controller: 'RouteController'
}).
when('/route2', {
templateUrl: '/Views/Modules/page2.html',
controller: 'RouteController'
}).
otherwise({
redirectTo: '/'
});
}]);

app.controller("RouteController", function ($scope) {

});


Just in case it's needed, here's my HomeController.cs



/Controllers/HomeController.cs:



public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}

public ActionResult page1()
{
return View();
}

public ActionResult page2()
{
return View();
}

public ActionResult About()
{
ViewBag.Message = "Your application description page.";

return View();
}

public ActionResult Contact()
{
ViewBag.Message = "Your contact page.";

return View();
}
}


Chrome's console tells me that app.js's references to page1 and
page2 are inaccurate, no matter what I do.
Could someone help me understand what's going on?

Web Development

I am currently converting an AngularJS HTML app to ASP.NET MVC and
I have laid out pretty much everything and but when the page loads I
see the controller(dashboard.js) but its not firing any function from
the dashboard controller here is what I'm doing:



in my _layout.cshtml I have the following:



<html ng-app="app_angular" >
<head>
<script src="~/script/angular/angular.js"></script>
<script
src="~/script/angular/angular-route.js"></script>
<script
src="~/script/angular/angular-resource.js"></script>
<script
src="~/script/angular/angular-animate.js"></script>
<script
src="~/script/angular/angular-cookies.js"></script>

<script src="~/script/js/jquery.min.js"></script>
<script src="~/script/js/bootstrap.min.js"></script>


<script src="~/Scripts/myapp.js"></script>
<script
src="~/Scripts/controllers/dashboard.js"></script>
<script src="~/Scripts/routes.js"></script>
</head>
<body>

<ng-view class="fx fx-slide page"></ng-view>

<div class="container">
<h3 class="row title">
<div class="col-xs-6">Dashboard</div>
<div class="col-xs-6 text-right text-gray">{{ today |
date:'MMMM d, y' }}</div>
</h3>
</div>
<section ng-repeat="template in templates">
<ng-include src="template"></ng-include>
</section>
<div class="container" ng-init="init()">

<!-- Buttons -->


</body>
</html>


myapp.js



var app_angular = angular.module('app_angular',
['ngCookies', 'ngRoute', 'ngResource', 'ngAnimate']);


dashboard.js



'use strict';
app_angular
.controller('dashboard', function ($rootScope, $scope) {
debugger
$scope.today = new Date();

/* set template subviews */
$scope.templates = {
stream: "../../views/templates/firstqtr.html",
modal: "../../views/templates/secondqtr.html",
loan: "../../views/templates/thirdqtr.html"
};

});


routes.js(first approach: does not work)



app_angular
.config(function($routeProvider, $httpProvider) {

$routeProvider
/* dashboard */
.when('/', {
controller: 'dashboard',
templateUrl: '../../views/home/index'
})
.when('/home/about', {
controller: 'dashboard',
templateUrl: '../../views/home/about'
})
.otherwise({
redirectTo: '/'
});
});


routes.js(second approach: does not work)



app_angular 
.config(['$routeProvider', function ($routeProvider)
{
$routeProvider
.when('/', { templateUrl: '/home/index', controller:
'dashboard' })
.when('/', { templateUrl: '/home/about', controller:
'dashboard' })

.otherwise({ redirectTo: '/home' });
}])


What else I should be doing any help?

Web Development

i'm trying to pass data from AngularJS to ASP.net MVC and is always
getting null.
Here's my code (only posting the essencial, button, controller and
c#:



HTML:



<a class="btn btn-grey btn-lg btn-block"
ng-click="AddCar()">Save</a>


Controller



$scope.AddGroup = function () {
$http.post("Cars/AddCar",
JSON.stringify($scope.new.JsonCar)).success(function (data) {
Alert(ok)
})


c#



public string AddCar(string JsonCar) 
{
try
....
}


In JSON.stringify($scope.new.JsonCar) i'm sending this:




"{"Name":"FIAT 500","Description":"New
car","MaxUserCapacity":5,"PhotoPath":"none"}"




What i'm doing wrong?

Web Development

I have followed Angular Seed Project but still I need to know what
is the best approach for creating AngularJs baed SPA in ASP.net MVc
.



I want to host common Business Logic layer through WebAPI( those
can be consumed from HTML client as well as smart Phone apps clinet),
Can we manage session effectively there in WebAPI project.



If I create HTMl client web app in entirely client side
technologies (css,html,js) then I think I will not be able to do
minifications of all js files and if yes then what is the
approach.



If anyone knows about sample web apps using these appraoches please
share link..



This is the project structure I am following as of now..
enter image<br />
description here

Web Development

I use ASP.MVC project to create the root page and Web API and
AngularJS for the supsite.



The AngularJS controller look like :



angular.module('myApp').controller('dummyController',
['$scope', '$http', function ($scope, $http) {

$scope.getData = function () {
$http({ method: 'GET', url: 'api/dummy/get' }).
success(function (data, status, headers, config) {
}).
error(function (data, status, headers, config) {
});
};

$scope.getData();

}]);


The Web API controller look like (the API controllers are in
/Controllers/Api) :



[RoutePrefix("api/dummy")]
public class DummyController : ApiController
{
[Route("get")]
[HttpGet]
public DummyAnswer Get()
{
return new DummyAnswer();
}
}


When I load the page, I get this error :



{"Message":"An error has occurred.","ExceptionMessage":"No
OWIN authentication manager is associated with the
request.","ExceptionType":"System.InvalidOperationException","StackTrace":"
at
System.Web.Http.Owin.PassiveAuthenticationMessageHandler.SuppressDefaultAuthenticationChallenges(HttpRequestMessage
request)
at
System.Web.Http.Owin.PassiveAuthenticationMessageHandler.<SendAsync>d__0.MoveNext()
--- End of stack trace from previous location where exception was
thrown ---
at
System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task
task)
at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task
task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at System.Web.Http.HttpServer.<SendAsync>d__0.MoveNext()"}


I disabled owin with :



<appSettings>
<add key="owin:AutomaticAppStartup" value="false" />
</appSettings>


Removed the startup class and other classes I don't use OWIN. The
assemblies are still referenced.



Could you help me ?



Thanks,

Web Development

I started learning AngularJS and ASP.NET MVC, but am not sure why
to use them both together in the same project?



Aren't they both MVC frameworks? Should I be using them both in the
same application? Isn't it one or the other?

Programming Languages

- Technology - Languages
+ Webmasters
+ Development
+ Development Tools
+ Internet
+ Mobile Programming
+ Linux
+ Unix
+ Apple
+ Ubuntu
+ Mobile & Tablets
+ Databases
+ Android
+ Network & Servers
+ Operating Systems
+ Coding
+ Design Software
+ Web Development
+ Game Development
+ Access
+ Excel
+ Web Design
+ Web Hosting
+ Web Site Reviews
+ Domain Name
+ Information Security
+ Software
+ Computers
+ Electronics
+ Hardware
+ Windows
+ PHP
+ ASP/ASP.Net
+ C/C++/C#
+ VB/VB.Net
+ JAVA
+ Javascript
+ Programming
Privacy Policy - Copyrights Notice - Feedback - Report Violation 2018 © BigHow