mardi 19 novembre 2019

How to check if a file exist or not using if statement?

I am trying to check if a booking field exist, then show its details. otherwise return to Bookparking page. but else part isn't working and shows Object reference not set to an instance of an object because there is no such field with the Session[""]

controller

public ActionResult Viewparking()
                { if (IsUserLoggedIn(Session, Request) == false)
                    {
                        return RedirectToAction("login");
                    }
                    else {
                          String id = Session["username"].ToString();
                          ViewBag.userid = id;
                         var checkbooking = db.tb_booking.Where(s => s.username == id ).FirstOrDefault();
                            if (checkbooking != null)
                            { var show = db.tb_booking.Where(e => e.username == id).FirstOrDefault();
                            }
                            else 
                            {   //ViewBag.f = "You have no booking yet!!";
                                return RedirectToAction("Bookparking", "user");
                            }
                      return View();
                    } }

Aucun commentaire:

Enregistrer un commentaire