0

I am new to Angularjs and I am building a ASP.NET MVC 6 application with some Angularjs views, I got an issue to pass parameter from MVC action link to the AngularJS controller, my url from MVC action link is as:http://localhost/Sites/Details/1, in my Details.cshtml page hosting the Angularjs to show Site location maps,

In my MVC Route:

routes.MapRoute( name: "default", template: "{controller=Home}/{action=Index}/{id?}");

In my MVC codes are as:

public JsonResult GetSiteInfo(int SiteId) { var sList = _context.Station.Where(s => s.Category.Site.SiteID == SiteId); return Json(sList); }

Angularjs codes are as:

var app = angular.module('myApp', ['uiGmapgoogle-maps','ngRoute']);
app.controller('mapController', function ($scope, $http,$window, $location, $routeParams, SiteID) {
var sid = SiteID.get({ id: $routeParams.someId });

    //Populate Site location information by site ID
    $http.get('/Sites/GetSiteInfo').
    params: {
            siteId: siteId
        }
    }).then(function (data) {
        $scope.locations = data.data;
    }, function () {
        alert('Error');
    });

I want to retrieve the siteId parameter from the URL in Angularjs and filter the result, currently I cannot retrieve the parameter from the URl in my Angularjs code, I am not sure what I did wrong, please advise.

Update: I found a resolved similar post from this link, but it seems not work for me, getting parameters from url in angularjs controller,

1 Answer 1

0

Try $routeParams.siteId in controller.

console.log("site id = "+$routeParams.siteId);
Sign up to request clarification or add additional context in comments.

1 Comment

thanks, I have tried, it did not work, I have updated my codes, seems still not work

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.