代码之家  ›  专栏  ›  技术社区  ›  omkar

在Ionic 4中转换为C#datetime时获得“无法将<Ionion datetime>序列化为字符串”

  •  0
  • omkar  · 技术社区  · 7 年前

    我正努力在爱奥尼亚系列化日期。

    我的模型是:

    export class Learner {
        name: string;
        phone: number;
        email:string;
        address: string;
        photo: string;
        dob: any;
        id:number;
        uid:string;
    }
    

    Html

      <ion-label>DOB</ion-label>
          <ion-datetime displayFormat="DD MMM, YYYY"  formControlName="dob" placeholder="Date of birth"></ion-datetime>
        </ion-item>
    

    Ts:

         var learner:Learner=
          {
            name: this.learnerOnboardForm.value.name,
            phone: parseInt(this.learnerOnboardForm.value.phone),
            email: this.learnerOnboardForm.value.email,
            address: this.learnerOnboardForm.value.address,
    /* trying to serialize this*/        
    dob:moment(this.learnerOnboardForm.value.dob).format('MMMM Do YYYY,h:mm:ss a'),
            photo:this.learnerOnboardForm.value.photo,
            id:0,
            uid:this.fUserCred.user.uid
          };
    

    我正试图保存日期并将其发送给c#controller。我试过date,datetime,其他人最终发现唯一的方法就是字符串。

    如果我从formcontrol记录值,则它是一个数组:

    iondatetime value from control

    我试着随着时间改变格式。js上面写着“无效日期”。

    我试着转换成日期,也就是“无效日期”。

    C#控制器

    [HttpPost]
            public async Task<IActionResult> Add ([FromBody]Learner l)
            {
              await this.learnerCommandLogic.Add(l);
              return Ok("learner added sucessfully");
            }
    
    public class Learner : BaseBusinessEntity
        {
            public string Uid { get; set; }
    
            [Required]
            public string  Name { get; set; }
    
            [Required]
            public double Phone { get; set; }
    
            [EmailAddress]
            [Required]
            public string Email { get; set; }
    
            public string Address { get; set; }
    
            public string Photo { get; set; }
    
            public string Dob { get; set; }
    
        }
    

    应用程序编程接口。学习者日志

    http://localhost:8100/api/Learners
    

    我收到了错误的请求,因为日期没有序列化

    主要问题是日期是以3个对象的Json形式出现的,分别是月、日、年。

    i want to send it as a single string of datetime like '10/09/2016 ...'
    
    0 回复  |  直到 7 年前
    推荐文章