Quantcast
Channel: ADO.NET, Entity Framework, LINQ to SQL, NHibernate
Viewing all articles
Browse latest Browse all 1698

Circular Reference json serialize object in c# mvc

$
0
0

Hi,

i want to get data in json format. but i'm getting response in string format so how can i resolve  this  issue,

 [HttpGet]
        public JsonResult DriverLogin(string username, string password, string GcmId)
        {
            _db.Configuration.ProxyCreationEnabled = false;
            var result = new
            {
                controller = "mobile",
                action = "DriverLogin",
                status = "OK"
            };

            try
            {
                var driver = _db.DRVR_DATA.Where(d => d.LoginName == username && d.Password == password && d.IsDeleted == false).FirstOrDefault(); //&& d.IsLogOut == true


                if (driver != null)
                {
                    driver.IsActive = true;
                    driver.LoginTime = DateTime.Now.ToUniversalTime();
                    driver.GcmId = GcmId;
                    driver.IsLogOut = false;
                    _db.Entry(driver).State = EntityState.Modified;
                    _db.SaveChanges();



                    SaveAuthsession(driver.DriverId);
                    var authData = _db.AuthorisedSessions.Where(d => d.DriverId == driver.DriverId).FirstOrDefault();
                    result = new
                    {
                        controller = "mobile",
                        action = "DriverLogin",
                        status = "OK"
                    };



                    var response = new
                    {
                     result,
                      driver,
                      authData
                    };


                    return Json(response, JsonRequestBehavior.AllowGet);


                }
                else
                {
                    var error = "Invalid User Name & Password ";
                    result = new
                    {
                        controller = "mobile",
                        action = "DriverLogin",
                        status = "NOK"
                    };
                    var response = new
                    {
                        result,
                        error
                    };
                    return Json(response, JsonRequestBehavior.AllowGet);
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)
            {
                Exception raise = dbEx;


            }
        }


Viewing all articles
Browse latest Browse all 1698

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>