Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/474.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript angularjs以json格式将数据发布到mvc控制器_Javascript_Json_Asp.net Mvc_Angularjs_Asp.net Mvc 4 - Fatal编程技术网

Javascript angularjs以json格式将数据发布到mvc控制器

Javascript angularjs以json格式将数据发布到mvc控制器,javascript,json,asp.net-mvc,angularjs,asp.net-mvc-4,Javascript,Json,Asp.net Mvc,Angularjs,Asp.net Mvc 4,我正在从事一个使用angularjs和mvc的项目。我正在通过$http.post()将数据从angularjs控制器传递到我的mvc控制器。目前,我正在使用frombody属性检索如下数据-公共字符串GetIssuedDescription([frombody]dynamic issueId)。但如果我可以这样做,我希望这样做 公共字符串GetIssueDescription(int-issueId) angularjs控制器代码 //show issue details $scope.sh

我正在从事一个使用angularjs和mvc的项目。我正在通过$http.post()将数据从angularjs控制器传递到我的mvc控制器。目前,我正在使用frombody属性检索如下数据-公共字符串GetIssuedDescription([frombody]dynamic issueId)。但如果我可以这样做,我希望这样做 公共字符串GetIssueDescription(int-issueId)

angularjs控制器代码

 //show issue details
$scope.showIssueDetails = function (issue) {
    //$scope.issueCount = 2;
    $scope.issueDetailsLoaded = false;
    $scope.selectedIssue = issue;
    $scope.statusName = issue.StatusName;
    var issueId = issue.Id;
    var url = window.location.protocol + '//' + window.location.host + '/api/Issues' + '/GetIssueDescription/';
    $http.post(url, JSON.stringify({ issueId: issueId })).success(function (data, status, headers, config) {
        if (data != '' || data.length >= 0) {
            $scope.selectedIssue.Description = $sce.trustAsHtml(angular.fromJson(data));
            $scope.selectedIssue = issue;
            $scope.showedit = true;
            $scope.showeditdesc = true;

            //setting default properties
            //$scope.issue.DueDate = $scope.selectedIssue.DueDate;
            $scope.getIssueComment($scope.selectedIssue);
            $scope.issueDetailsLoaded = true;
        }
        else if (data == '') {
            $scope.selectedIssue.Description = "";
        } else {
            $scope.errors.push(data.error);
        }
    });
    if($scope.isVisible==false) {
        $("#changedetailsbox").hide();
        $scope.isVisible = true;
    }
    if ($scope.isVisibleReply == false) {
        $("#postReplybox").hide();
        $scope.isVisibleReply = true;
    }
};
  [HttpPost]
    [AuthenticationRequired]
    public string GetIssueDescription([FromBody]dynamic issueId)
    {
        try
        {
            var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(issueId.ToString());
            var selectedIssueId = new Guid(dictionary["issueId"]);
            var result = PublicLayer.GetIssueDescription(selectedIssueId);
            return result.IsSuccessful ? result.Result : string.Empty;
        }
        catch (Exception ex)
        {
            BLL.Base.BaseLayer.WriteApplicationLog(ex);
            return string.Empty;
        }
    }
MVC控制器代码

 //show issue details
$scope.showIssueDetails = function (issue) {
    //$scope.issueCount = 2;
    $scope.issueDetailsLoaded = false;
    $scope.selectedIssue = issue;
    $scope.statusName = issue.StatusName;
    var issueId = issue.Id;
    var url = window.location.protocol + '//' + window.location.host + '/api/Issues' + '/GetIssueDescription/';
    $http.post(url, JSON.stringify({ issueId: issueId })).success(function (data, status, headers, config) {
        if (data != '' || data.length >= 0) {
            $scope.selectedIssue.Description = $sce.trustAsHtml(angular.fromJson(data));
            $scope.selectedIssue = issue;
            $scope.showedit = true;
            $scope.showeditdesc = true;

            //setting default properties
            //$scope.issue.DueDate = $scope.selectedIssue.DueDate;
            $scope.getIssueComment($scope.selectedIssue);
            $scope.issueDetailsLoaded = true;
        }
        else if (data == '') {
            $scope.selectedIssue.Description = "";
        } else {
            $scope.errors.push(data.error);
        }
    });
    if($scope.isVisible==false) {
        $("#changedetailsbox").hide();
        $scope.isVisible = true;
    }
    if ($scope.isVisibleReply == false) {
        $("#postReplybox").hide();
        $scope.isVisibleReply = true;
    }
};
  [HttpPost]
    [AuthenticationRequired]
    public string GetIssueDescription([FromBody]dynamic issueId)
    {
        try
        {
            var dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(issueId.ToString());
            var selectedIssueId = new Guid(dictionary["issueId"]);
            var result = PublicLayer.GetIssueDescription(selectedIssueId);
            return result.IsSuccessful ? result.Result : string.Empty;
        }
        catch (Exception ex)
        {
            BLL.Base.BaseLayer.WriteApplicationLog(ex);
            return string.Empty;
        }
    }
请建议是否可以像这样在我的方法公共字符串GetIssueDescription(Issue Issue)中使用my this类,并可以使用Issue.id检索我的id。请建议如何在控制器中实现此目的。

改变

public string GetIssueDescription([FromBody]dynamic issueId)

在你的角上

var issueId = issue.Id;
.
.
$http.post(url, { Id: issueId }).success(function (data, status, headers, config) {

1-您不需要严格化。2-为您的问题创建一个属性为int-issueID的模型,然后将GetIssueDescription(int-issueID)更改为GetIssueDescription(Issue-Issue)。您使用的是API控制器(根据URL)还是仅使用MVC控制器??首先检查你的网址。而且也不需要在angularjs的http post中使用JSON.stringify。您可以使用类似于$http.post('url?issueId='+issueId,).success(函数(数据、状态、标题、配置){//do anythis with data}。如果您没有使用API控制器并且没有定义自定义路由,那么您的URL是错误的。是的,我正在使用API控制器,请查看我的更新代码,并建议如何使用它检索我的int ID。请查看下面我的回答