I have an application that uses both ASP.NET MVC and Angularjs. I'm using the Angularjs $location provider to modify the search part of the url when filters are added or removed.
我有一个使用两个ASP的应用程序。净MVC和Angularjs。当添加或删除过滤器时,我使用Angularjs $location提供程序修改url的搜索部分。
$location.search(searchObj);
I am then subscribing to the $locationChangeSuccess event and using signalr to update the data on the page without requiring an asp.net post each time a filter is changed.
然后,我订阅了$locationChangeSuccess事件,并使用signalr更新页面上的数据,每次更改过滤器时不需要asp.net post。
$scope.$on('$locationChangeSuccess', onRouteChanged, false);
All of the above works, however, I also have some mvc action links on the page that I need to work when clicked.
但是,上面所有的工作,我也有一些mvc操作链接在页面上,我需要在点击的时候工作。
<a href="@(Url.Action("Details", "Video"))/{{item.id}}">
...
</a>
Unfortunately, when clicking those links, the url is updated but the mvc post doesn't happen. If anyone knows how to make this work I would be grateful.
不幸的是,当单击这些链接时,url会被更新,但是mvc不会发布。如果有人知道怎么做,我会很感激。
1 个解决方案
#1
2
By default, the link in directive a
is handled by AngularJS's route module. If you want to make a API request, you can make the call using $http
module either wrapped in a service or factory or just in the controller.
默认情况下,指令a中的链接由AngularJS的路由模块处理。如果想发出API请求,可以使用$http模块进行调用,该模块可以封装在服务或工厂中,也可以只封装在控制器中。
Try this:
试试这个:
<a href="" ng-click="showVideo(@(Url.Action("Details", "Video"))/{{item.id}})">
$scope.showVideo = function (url) {
$http.get { method: 'GET', url: url }).
success(function (data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
}).
error(function (data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
}
#1
2
By default, the link in directive a
is handled by AngularJS's route module. If you want to make a API request, you can make the call using $http
module either wrapped in a service or factory or just in the controller.
默认情况下,指令a中的链接由AngularJS的路由模块处理。如果想发出API请求,可以使用$http模块进行调用,该模块可以封装在服务或工厂中,也可以只封装在控制器中。
Try this:
试试这个:
<a href="" ng-click="showVideo(@(Url.Action("Details", "Video"))/{{item.id}})">
$scope.showVideo = function (url) {
$http.get { method: 'GET', url: url }).
success(function (data, status, headers, config) {
// this callback will be called asynchronously
// when the response is available
}).
error(function (data, status, headers, config) {
// called asynchronously if an error occurs
// or server returns response with an error status.
});
}