此代码不使用仅角度MCV,但当我将文件返回到Angular JS时,无法在浏览器上下载pdf。我认为问题在于
generateForm(contactId: number, remarks: string): void {
this.orderFactory.generateForm(this.$stateParams['orderId'], this.$stateParams['priority'], contactId, remarks).then((response) =>
我测试了许多方法,但我不知道。我该怎么办?
public class CoverVM
{
public int? OrderId { get; set; }
public int? Priority{ get; set; }
public int? ContactId { get; set; }
public string Remarks { get; set; }
}
MCV控制器
[HttpPost]
public ActionResult Cover(CoverVM Model)
{
Order order = db.Orders.Find(Model.OrderId);
var location = order.OrderLocations.Where(p => p.LocationPriority == Model.Priority).FirstOrDefault();
var opposing = order.OrderCounsils.FirstOrDefault();
var otherdelivery = order.OrderOtherDeliveries.FirstOrDefault();
var AttachmentFiles = order.AttachmentFiles.FirstOrDefault();
if (order != null)
{
string fileName = order.OrderNo.HasValue ? "Cover"+ order.OrderNo.Value.ToString() : "Cover";
fileName += (Model.Priority + "-" + Model.ContactId + ".pdf");
var pdfPath = Path.Combine(Server.MapPath("~/Content/Forms/Reports"), "Cover.pdf");
if (order!= null){
try {
.........
}
catch (Exception ex)
{
Debug.Print(ex.ToString());
}
finally
{
stamper.Close();
}
return File(outPutFilePath, "application/pdf", fileName);
}
return null;
}
角度视图 Cover.html
<md-input-container class="md-block" flex-gt-sm>
<label>Delivery To {{vm.deliveryPartyId}}</label>
<md-icon md-svg-icon="communication:location_on" title="{{vm.deliveryParties.id}}"></md-icon>
<md-select ng-model="vm.deliveryPartyId" name="contactId" required ng-change="vm.onPartySelect(vm.deliveryPartiesId)">
<md-optgroup label="{{currentGroup}}" ng-repeat="currentGroup in vm.deliveryGroups">
<md-option ng-repeat="party in vm.deliveryParties | filter: {group: currentGroup}"
ng-value="party.id" ng-disabled="{{party.disabled}}">
{{party.title}}
</md-option>
</md-optgroup>
</md-select>
</md-input-container>
<md-input-container class="md-block" flex-gt-sm="50">
<label>Additional Information</label>
<textarea ng-model="vm.remarks" rows="5" md-maxlength="256" name="remarks"></textarea>
</md-input-container>
<md-button aria-label="Generate Cover PDF" ng-click="vm.generateForm(vm.deliveryPartyId, vm.remarks)" ng-disabled="!vm.deliveryPartyId">
<md-icon md-svg-icon=""></md-icon> Generate Cover PDF
</md-button>
Angular Controller cover.controller.ts
module app.order.admin {
'use strict';
export class CoverController {
reportWcab: IOrder;
title: string;
locations: IOrderLocation;
deliveryParties: Array<any>;
deliveryGroups: Array<any>;
remarks: string;
data: any;
static $inject = ['$state', '$stateParams', 'orderFactory', 'toastAlert', '$scope'];
constructor(
private $state: ng.ui.IStateService,
private $stateParams: ng.ui.IStateParamsService,
private orderFactory: app.order.IOrderAdminFactory,
private toastAlert: app.IToastAlert,
private $scope: any
) {
............................
........................................
generateForm(contactId: number, remarks: string): void {
this.orderFactory.generateForm(this.$stateParams['orderId'], this.$stateParams['priority'], contactId, remarks).then((response) => {
// What can I to do download the pdf??
// window.location.href = "/Form/Cover/?Model=" + this.data;
console.log('response', response);
this.toastAlert.showToaster("ok");
});
}
} angular
.module('app.order.admin')
.controller('ReportController', CoverController);
}
在OrderFactory上
generateForm(orderId: number, priority: number, contactId: number, remarks: string): ng.IPromise<any> {
var data = {
OrderId: orderId,
Priority: priority,
ContactId: contactId,
Remarks: remarks || ''
};
return this.$http.post('/Form/Cover', data).then(this.handleSuccess, this.handleError);
}