C# 如何以“得到”作为承诺发帖子
现在,我可以选择数据库中已经存在的作业,并将其发送到web api控制器以导出为PDF。我现在需要创建一个作业,并将其发送到转换的同时。所以我需要一些帮助,告诉我最好的方法是什么?我是否需要发布它,然后有一个函数来调用一个操作,该操作获取数据库中创建的最新作业?或者我可以在表单发出POST之前,以某种方式将表单转换为可以传递给Api控制器的对象吗?我认为后者会更简单,但我认为将对象发送到api控制器的操作是GET调用?下面是我如何发送一个已经在db中的作业C# 如何以“得到”作为承诺发帖子,c#,angularjs,asp.net-web-api,angular-promise,C#,Angularjs,Asp.net Web Api,Angular Promise,现在,我可以选择数据库中已经存在的作业,并将其发送到web api控制器以导出为PDF。我现在需要创建一个作业,并将其发送到转换的同时。所以我需要一些帮助,告诉我最好的方法是什么?我是否需要发布它,然后有一个函数来调用一个操作,该操作获取数据库中创建的最新作业?或者我可以在表单发出POST之前,以某种方式将表单转换为可以传递给Api控制器的对象吗?我认为后者会更简单,但我认为将对象发送到api控制器的操作是GET调用?下面是我如何发送一个已经在db中的作业 <div class="inli
<div class="inline-fields">
<label>JobId:</label>
<input ng-model="currentItem.JobId" type="text">
<label>JobName:</label>
<input ng-model="currentItem.JobName" type="text">
</div>
<input ng-click="EmailPdf(currentItem)" type="button" value="Email"/>
Api控制器
$scope.EmailPdf = function () {
var id = $scope.currentItem.JobId
$http.get('/api/Pdf/' + id).success(function () {
$scope.PrintPreviewModal();
});
}
public string Get(int? id)
{
if (!id.HasValue)
{
return string.Empty;
}
JobDataAdapter adapter = new JobDataAdapter();
Job job = new Job();
job = adapter.GetJob(id);
if (job == null)
{
return string.Empty;
}
try
{
这就是我创建工作的方式
<div class="inline-fields">
<label>Number:</label>
<input ng-model="currentItem.JobNumber" type="text">
</div>
<div class="inline-fields">
<label>Address:</label>
<input ng-model="currentItem.CustomerAddress" type="text">
</div>
<div class="inline-fields">
<label>Name:</label>
<input ng-model="currentItem.JobName" type="text">
</div>
<input type="submit" value="Save" />
<input ng-click="EmailPdf()" type="button" value="Email" />
//Post New Job
$scope.submitJob = function () {
var data = {
JobNumber: $scope.currentItem.JobNumber,
JobName: $scope.currentItem.JobName,
CustomerAddress: $scope.currentItem.CustomerAddress,
}
$http.post('/api/apiJob/PostNewJob', data).success(function (data, status, headers) {
console.log(data); window.top.location.reload();
});
};
编号:
地址:
姓名:
//发布新工作
$scope.submitJob=函数(){
风险值数据={
作业编号:$scope.currentItem.JobNumber,
JobName:$scope.currentItem.JobName,
CustomerAddress:$scope.currentItem.CustomerAddress,
}
$http.post('/api/apiJob/PostNewJob',data.).success(函数(数据、状态、标题){
console.log(数据);window.top.location.reload();
});
};
如果我理解您的意图,您可以通过PostNewJob调用的成功来调用pdf函数。比如:
$http.post('/api/apiJob/PostNewJob', data).success(function (data, status, headers) {
console.log(data);
// use the new object to call the Pdf api
$http.get('/api/Pdf/' + data.id).success(function () {
$scope.PrintPreviewModal();
window.top.location.reload();
});
});
是的,那正是我想要的。但是id已经创建好了吗?是自动在服务器端创建的,对吗?我可以使用其他属性,例如JobNumber吗?