【发布时间】:2020-01-21 20:15:28
【问题描述】:
我对 C# 还很陌生,我完全不知道接下来应该做什么来处理我用 Bootstrap 和 Html 以及 AngularJS 控制器创建的输入表单中的用户输入。
每次我尝试使用我的 api 的 Get 方法返回值时,我的整个控制器都会中断。
我已经阅读了很多关于 RESTful api web 方法的教程和诀窍,我开始对它感到困惑和过度思考,因为我知道这是一个简单的过程。
下面是我的控制器的代码:
public class FeedbackController : ApiController
{
// GET: api/Feedback
public IEnumerable<string> Get()
{
return new string[] { "value1", "value2" };
}
// GET: api/Feedback/
public string (Feedback id);
{
}
// POST: api/Feedback
public void Post([FromBody]Feedback value)
{
}
// PUT: api/Feedback
public void Put( [FromBody]Feedback value)
{
var test = value.FeedbackRating;
}
// DELETE: api/Feedback/
public void Delete(Feedback id)
{
}
public string post([FromUri]Feedback value)
{
return "Put returning: " + value;
}
//angular js
commonModule.controller('feedbackController', ['$scope', '$modal', ' $timeout', 'authenticationService',
function ($scope, $modal, $timeout, authenticationService) {
var init = function () {
$scope.feedbackPopup();
}
$scope.feedbackPopup = function () {
var modalInstance = $modal.open({
templateUrl: '/Scripts/app/common/views/popup.tpl.html',
resolve: {
},
controller: function ($scope, $modalInstance) {
$scope.close = function () {
$modalInstance.close();
};
$scope.submitFeedback = function () {
$scope.feedback = {
FeedbackRating: 1,
FeedbackSubject: 1,
FeedbackUpload: 1,
FeedbackDescription:1
};
authenticationService.submitFeedback($scope.feedback).then(
// Success Handler
function (result) {
$modalInstance.close();
$scope.message = "Feedback submitted";
$timeout(function () {
$scope.message = "";
}, 3000);
},
// Failure Handler
function () {
$scope.message = "Error updating specialization";
});
}
}
});
}
init();
}]);
})();
Feedback class
{
public class Feedback
{
public int FeedbackRating { get; set; }
private string EncryptedHexPuid { get; set; }
public string FeedbackDescription { get; set; }
public string FeedbackSubject { get; set; }
}
}
【问题讨论】:
-
你能发布你的 Angular 控制器代码吗?特别是您的
$http电话,但最好更多 -
当您说
every time I try to return values with my Get methods for my api, my whole controller breaks.时,您的意思是您的 angular.js 控制器正在进行 $http 调用还是您的 wep api 控制器正在处理请求? -
当您在浏览器中点击您的 api URL 时,您会得到预期的响应吗?
-
我将发布我的 Angular 控制器。
-
还有 sgwatstack,我的意思是代码不再运行并且帖子中断。意味着存在代码问题。出现的问题是预期的类、委托、枚举、接口或结构。'
标签: c# angularjs rest asp.net-web-api