1

我想将当前日期和时间存储在数据库中,所以我在角度使用 Moment。

我想为时刻类型的 DateTime 分配空白值。

就像 InvoiceId 是一个数字一样,分配 0 的方式与分配字符串 '' 的方式类似。如何为矩类型分配空白值?

Web API 模型:

public class Invoice

{
    [Key]
    public int InvoiceId { get; set; }
    [Required]
    public int Tax { get; set; }
    [Required]
    public int GrandTotal { get; set; }
    [Required]
    public DateTime DateTime { get; set; }

    public virtual ICollection<SalesTransaction> SalesTransactions { get; set; }

}

角文件:

   currentTime: any;

   invoiceData = {

   InvoiceId: 0,
   Tax: 0,
   GrandTotal: 0,
   DateTime: 

};
   this.invoiceData.DateTime = this.currentDateTime;


    this.serviceInvoice.createInvoice(this.invoiceData).subscribe(( dataInvoice ) => {
      console.log('Invoice -', dataInvoice);

    )};

角度接口:

import { Moment } from 'moment';

export interface InvoiceElement {

InvoiceId: number;
Tax: number;
GrandTotal: number;
DateTime: Moment;

}
4

0 回答 0