0

My layout.cshtml contains:

    <li><a href="#/User">User</a></li>
<div ng-view></div>

This is my controller:

enter image description here

and its action methods:

public class UserController : Controller

{
    // GET: Admin/Default
    BMS2Entities _db = new BMS2Entities();
    public ActionResult Index()
    {
        var emp = _db.AspNetUsers.ToList();
        return Json(emp, JsonRequestBehavior.AllowGet);
    }

And index.cshtml and index.js file inside:

enter image description here

index.js contains server call to usercontroller inside admin area:

app.controller('userController', function ($scope, $http) {

$http({ method: 'Get', url: 'Areas/Admin/User/Index' })
            .then(function (response) {
                $scope.depts = response.data;
            });

});

and finally myapp.js file for routing:

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

app.config(function ($routeProvider) {

$routeProvider.when('/User', {
    templateUrl: 'Areas/Admin/Views/User/Index.cshtml',
    controller: 'userController'
});

$routeProvider.otherwise({
    redirectTo: '/'
});

});

but the codes are not working and it does not display cshtml and shows https://localhost:44382/Common/Home#/User in the browser.

2 Answers 2

1

$routeProvider.when('/User', { templateUrl: 'Areas/Admin/Views/User/Index.cshtml', controller: 'userController' });

You need to prefix root path in templateUrl and same thing in while calling controller's action.

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

Comments

0

Did you write ng-app directive in layout.cshtml? And I think the syntax for tag should be like

<a href="/#/User">User</a> 

Hope this Helps!

Comments

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.