嗨,我正在使用asp.net mvc在angular 7应用程序上工作。
我正在尝试将上传的文档保存到数据库中。
这是保存数据的方法:
export class EditDiplomaComponent extends AfwComponent implements OnInit {
resources: DiplomasWijzigenResourcesModel;
private readonly apiDiploma: 'api/register/teachers/current/diploma';
readonly resourceKeys = DiplomasWijzigenResourcesModel.keys;
buttons: ImmutableArrayType<ButtonModel>;
protected readonly formName = FormNamesModel.diplomaForm;
formModel: AfwFormService;
documentList?: DocumentListModel;
documentListCompoment: DocumentListComponent;
diplomaFormKeysModel: DiplomaFormKeysModel;
protected baseDocumentsUrl: string;
teacher: TeacherModel;
constructor(
private readonly http: AfwHttp,
readonly route: ActivatedRoute,
readonly textResourceService: TextResourceService,
private readonly formService: FormService,
private readonly multiFileUploadControlFactory: MultiFileUploadControlFactory,
private readonly feedbackService: FeedbackStoreService,
private readonly router: Router,
) {
super(textResourceService, route);
}
ngOnInit(): void {
// this.baseDocumentsUrl = `api/register/teachers/current/diploma/${this.teacher.guid}/documents?fileName=`;
const defaultModel = diplomaFormModel(this.multiFileUploadControlFactory);
this.formModel = this.formService.createModel<DiplomaFormModel, DiplomasWijzigenResourcesModel>(
defaultModel, { qualificationTerms: null, diplomasUpload: this.multiFileUploadControlFactory.createEmptyDefaultValues() }, this.resources
);
const saveBtn = new ActionButtonModel({ resourceKey: this.resourceKeys.opslaanKnop, isSubmit: true });
const cancelBtn = new CancelLinkButtonModel();
this.buttons = ImmutableArrayType.Create([saveBtn, cancelBtn]);
}
diplomaDataSubmitted($event: AfwFormService) {
// const formModel = $event;
if (this.allowSubmitAgain && this.formModel.form.valid) {
const obs = this.saveDiploma(true, this.resources.opslaanSpinnerTekst).pipe(map(() => {
this.router.navigateByUrl(RoutesRegisterModel.pathnameMyRegisterRouteDiplomas).then(() => {
this.feedbackService.addSuccessMessage (
{
feedbackPortalKey: FeedbackPortalsModel.mainFeedback,
message: { key: 'succesvolWijziging', value: this.resources.succesvolWijziging },
});
});
}))
this.submitAllowed(obs);
}
}
saveDiploma(competenceStatement: boolean, spinnerMessage: string): Observable<any> {
return this.http.post(`${this.apiDiploma}`,
competenceStatement,
spinnerMessage);
}
}
这是文凭控制者:
[Authorize(Roles = IdentityRoles.Teacher)]
[RoutePrefix("api/register/teachers/current/diploma")]
public sealed class DiplomaController : ApiControllerBase
{
private readonly IDiplomaProcess _diplomaProcess;
/// <summary>
/// Constructor.
/// </summary>
public DiplomaController(IDiplomaProcess diplomaProcess)
{
_diplomaProcess = diplomaProcess;
}
/// <summary>
/// Create the diploma record for the current teacher.
/// </summary>
/// <param name="competenceStatement">Has agreed to the competence statement?</param>
[Route("")]
[HttpPost]
public void CreateDiploma(bool competenceStatement)
{
_diplomaProcess.CreateDiploma(competenceStatement);
}
/// <summary>
/// Delete the diploma record for the current teacher.
/// </summary>
[HttpDelete]
[Route("")]
public void DeleteDiploma()
{
_diplomaProcess.DeleteDiploma();
}
/// <summary>
/// Get the diploma documents of the current teacher.
/// </summary>
/// <returns>The DocumentListDto with the diploma documents.</returns>
[Route("")]
[HttpGet]
public DiplomaDto GetDiplomas()
{
return _diplomaProcess.GetDiplomas();
}
}
但是当我调试代码时,我在这一行看到了这一点:
return this.http.post(`${this.apiDiploma}`,
apDiploma未定义。我正在使用一个Observable。
但是我的想法是您必须订阅它。但是如何订阅该方法?
谢谢
谢谢。
但在这一行:返回this.http.post(${this.apiDiploma}
,
我看到正确的url: "api/register/teachers/current/diploma"
这是输出:
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<DiplomaDto xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/VLR.BackEnd.Dto.Teacher">
<Documents xmlns:d2p1="http://schemas.datacontract.org/2004/07/VLR.BackEnd.Dto.Document">
<d2p1:Documents/>
<d2p1:DocumentsInQueue>-2147483648</d2p1:DocumentsInQueue>
<d2p1:IsSucceeded>true</d2p1:IsSucceeded>
</Documents>
<HasAgreedToCompetenceStatement>false</HasAgreedToCompetenceStatement>
</DiplomaDto>
但是如果调试后端(控制器)
然后我看到它不是这种方法:
[Route("")]
[HttpPost]
public void CreateDiploma(bool competenceStatement)
{
_diplomaProcess.CreateDiploma(competenceStatement);
}
答案 0 :(得分:0)
我认为您要做的是将其定义为字符串类型并为其分配值
将该行更改为
private readonly apiDiploma: string = 'api/register/teachers/current/diploma';