How do I format a Microsoft JSON date?

后端 未结 30 3106
伪装坚强ぢ
伪装坚强ぢ 2020-11-21 04:48

I\'m taking my first crack at Ajax with jQuery. I\'m getting my data onto my page, but I\'m having some trouble with the JSON data that is returned for Date data types. Basi

30条回答
  •  名媛妹妹
    2020-11-21 04:57

    A late post, but for those who searched this post.

    Imagine this:

        [Authorize(Roles = "Administrator")]
        [Authorize(Roles = "Director")]
        [Authorize(Roles = "Human Resources")]
        [HttpGet]
        public ActionResult GetUserData(string UserIdGuidKey)
        {
            if (UserIdGuidKey!= null)
            {
                var guidUserId = new Guid(UserIdGuidKey);
                var memuser = Membership.GetUser(guidUserId);
                var profileuser = Profile.GetUserProfile(memuser.UserName);
                var list = new {
                                  UserName = memuser.UserName,
                                  Email = memuser.Email ,
                                  IsApproved = memuser.IsApproved.ToString() ,
                                  IsLockedOut = memuser.IsLockedOut.ToString() ,
                                  LastLockoutDate = memuser.LastLockoutDate.ToString() ,
                                  CreationDate = memuser.CreationDate.ToString() ,
                                  LastLoginDate = memuser.LastLoginDate.ToString() ,
                                  LastActivityDate = memuser.LastActivityDate.ToString() ,
                                  LastPasswordChangedDate = memuser.LastPasswordChangedDate.ToString() ,
                                  IsOnline = memuser.IsOnline.ToString() ,
                                  FirstName = profileuser.FirstName ,
                                  LastName = profileuser.LastName ,
                                  NickName = profileuser.NickName ,
                                  BirthDate = profileuser.BirthDate.ToString() ,
                };
                return Json(list, JsonRequestBehavior.AllowGet);
            }
            return Redirect("Index");
        }
    

    As you can see, I'm utilizing C# 3.0's feature for creating the "Auto" Generics. It's a bit lazy, but I like it and it works. Just a note: Profile is a custom class I've created for my web application project.

提交回复
热议问题