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,