Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.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
C# 如何将对象从角度控制器传递到ApiController_C#_Asp.net Mvc_Angularjs_Asp.net Web Api2 - Fatal编程技术网

C# 如何将对象从角度控制器传递到ApiController

C# 如何将对象从角度控制器传递到ApiController,c#,asp.net-mvc,angularjs,asp.net-web-api2,C#,Asp.net Mvc,Angularjs,Asp.net Web Api2,我正在尝试将对象Id传递给ApiController。现在什么都没有通过。也没有错误。现在,当我在Get Call中特别添加一个JobId时,一切都很好,所以我一直在研究如何使它与任何JobId一起工作 看法 高级控制器 $scope.EmailPdf = function () { id = $scope.currentItem.JobId $http.get('/api/Pdf/id').success(function () { $scope.PrintPr

我正在尝试将对象Id传递给ApiController。现在什么都没有通过。也没有错误。现在,当我在Get Call中特别添加一个JobId时,一切都很好,所以我一直在研究如何使它与任何JobId一起工作

看法

高级控制器

 $scope.EmailPdf = function () {
   id = $scope.currentItem.JobId
    $http.get('/api/Pdf/id').success(function () {
        $scope.PrintPreviewModal();
    });
}
 // GET api/<controller>/5
    public string Get(int? id) // allow nullable parameter
    {
        if (!id.HasValue) // if null return an empty string
        {
            return string.Empty;
        }

        // your code :
        JobDataAdapter adapter = new JobDataAdapter();
        Job job = new Job();
        job = adapter.GetJob(id);
        if (job == null)
        {
            return string.Empty;
        }

这是一种方式。根据API的复杂性,您还应该查看该服务。

您没有将id传递给您的ajax调用。已完成,谢谢。我考虑过切换到ngResource。是的,在您使用$http将相同的4个crud操作重写几次之后,$resource变得很有吸引力,而且IMO也很有价值(这也使得我确信可以在后端编写一致的RESTful位)。
 // GET api/<controller>/5
    public string Get(int? id) // allow nullable parameter
    {
        if (!id.HasValue) // if null return an empty string
        {
            return string.Empty;
        }

        // your code :
        JobDataAdapter adapter = new JobDataAdapter();
        Job job = new Job();
        job = adapter.GetJob(id);
        if (job == null)
        {
            return string.Empty;
        }
config.Routes.MapHttpRoute(
        name: "PdfApi",
        routeTemplate: "api/{controller}/{id}",
    defaults: new { controller = "apiGeneratePdf", id = RouteParameter.Optional }
    );
$scope.EmailPdf = function () {
   id = $scope.currentItem.JobId
    $http.get('/api/Pdf/' + id).success(function () {
        $scope.PrintPreviewModal();
    });
}