在 mvc 中使用 angularjs 和 restful web api 获取数据
Get data using angularjs with restful web api in mvc
我需要创建一个应用程序,该应用程序从存储过程中获取数据并将其显示在视图中。
当我将 id 从视图传递到 angularjs 控制器时,具有该字段的值,但无法在 web API 中获得相同的值,它显示 null(调用时)。
更具体地说,尝试了各种选项,其中一些如下:
- 二手 [来自正文]
- 将 json 中的字符串值从 angularjs 控制器传递到 webapi
因此,当它为 null 时,它总是抛出失败的结果,而不是成功。
请帮忙。
法典:
- Angularjs (controller)
app.controller('matchDetailController', function($scope, $http) {
$scope.getAllMatchDetail = function(matchId) {
var MatchId = matchId;
$http.get('/api/[Apicontrollername]/GetAllMatchDetail', MatchId).success(function(data) {
if (data.status == "success") {
} else {
}
}).error(function(error) {
debugger;
})
}
});
<div class="view_container" id="matchDetail" data-ng-controller="matchDetailController" data-ng-init="getAllMatchDetail(@ViewBag.MatchId)">
-
网络接口
public 对象 GetAllMatchDetail([FromBody]string MatchId) { SoccerWebviewMatchDetailRepository _SoccerWebviewMatchDetailRepository = new SoccerWebviewMatchDetailRepository();
List<clsSoccerWebviewMatchDetail> objlstclsSoccerWebviewMatchDetail = _SoccerWebviewMatchDetailRepository.getAllSoccerWebviewMatchDetail(MatchId); if (objlstclsSoccerWebviewMatchDetail != null && objlstclsSoccerWebviewMatchDetail.Count() != 0) { var jsonObject = new { status = "success", objlstclsSoccerWebviewMatchDetail = _SoccerWebviewMatchDetailRepository.getAllSoccerWebviewMatchDetail(MatchId) }; return jsonObject; } else { var jsonObject = new { status = "fail", message = "No match details found" }; return jsonObject; } }
检查代码。
首先这是 HttpGet 方法,你需要在 URL 中传递参数。
棱角分明.js
$http.get('/api/[Apicontrollername]/GetAllMatchDetail/'+ MatchId ).success(function(data) {
if (data.status == "success") {
} else {
}
}).error(function(error) {
debugger;
})
Web API : 删除 [从正文]
public object GetAllMatchDetail(string MatchId)
{
SoccerWebviewMatchDetailRepository _SoccerWebviewMatchDetailRepository = new SoccerWebviewMatchDetailRepository();
}
相关文章:
- 使用AngularJS消费RESTful Web服务
- 使用 HTML5 File API 将文件上传到 RESTful Web 服务
- RESTful Web 应用程序中的客户端服务器体系结构
- 在 mvc 中使用 angularjs 和 restful web api 获取数据
- 来自链接函数的Restful web service调用
- 为什么我的两个不同angularjs服务解析为同一个restful Java EE web服务
- Phonegap and restful web service
- AngularJS使用RESTful web服务身份验证
- 无法从angular js中的restful Web服务中提取数据
- 如何为RESTful web应用程序实现身份验证
- 使用POST调用RESTFUL web服务
- 如何从restful web服务中访问json对象的属性
- 如何在restful web服务中给出图表作为响应
- 如何在android中使用javascript从restful wcf web服务中检索数据
- web浏览器与RESTful API交互是一种很好的实践吗?
- 为Restful Web Service构建JSON配置的正确方法
- 带有Zend框架和Extjs的RESTFUL Web应用程序
- AngularJS RESTful Web Service -向表中添加行而不刷新
- 将剑道下拉列表绑定到RESTFUL web服务
- web服务-使用javascript调用expressjs restful webservice =>结果总是空的响应