Home > Blockchain >  I am getting Error in Asp.Net MVC "Cannot perform runtime binding on a null reference"
I am getting Error in Asp.Net MVC "Cannot perform runtime binding on a null reference"

Time:07-22

The project was working correctly with no exception, then i started to get this error suddenly. I searched this error on forums and figured something about Razor so i updated Visual Studio but nothing changed. Details as below:

cshtml:

               <div >
                    <div >

                        <h3> @ViewBag.countActivityFinish </h3>

                        <p>Tamamlanan Aktivite Sayısı</p>
                    </div>
                    <div >
                        <i ></i>
                    </div>
                    <a href="/Activity" >Aktiviteleri Gör <i ></i></a>
                </div>

controller:

public ActionResult Index()
    {
        if (Session["user"] == null) return RedirectToAction("Index", "Login");

        conn.Open();

        User withEmailToUser = conn.Query<User>("SELECT * FROM [User] WHERE Email = @Email", new User() { Email = Session["user"].ToString() }).FirstOrDefault();

        List<UserWrongLoginLog> userWrongLoginLogs = conn.Query<UserWrongLoginLog>("SELECT * FROM [UserWrongLoginLog] WHERE UserId = @UserId", new UserWrongLoginLog() { UserId = (Guid)withEmailToUser.Id }).ToList();    
        foreach (var item in userWrongLoginLogs)
        {
            conn.Execute("DELETE FROM [UserWrongLoginLog] WHERE Id=@Id", item);
        }

        int countCompany = conn.Query<int>("SELECT COUNT(*) FROM Company WHERE IsDelete = @IsDelete", new Company() { IsDelete = false }).FirstOrDefault();
        int countContact = conn.Query<int>("SELECT COUNT(*) FROM Contact WHERE IsDelete = @IsDelete", new Contact() { IsDelete = false }).FirstOrDefault();
        int countActivityWaiting = conn.Query<int>("SELECT COUNT(*) FROM Activity WHERE Status = @Status", new Activity() { Status = 0 }).FirstOrDefault();
        int countActivityFinish = conn.Query<int>("SELECT COUNT(*) FROM Activity WHERE Status != @Status", new Activity() { Status = 0 }).FirstOrDefault();

        conn.Close();

        withEmailToUser.UserWrongLoginLogs = userWrongLoginLogs;

        ViewBag.countCompany = countCompany;
        ViewBag.countContact = countContact;
        ViewBag.countActivityWaiting = countActivityWaiting;
        ViewBag.countActivityFinish = countActivityFinish;
        ViewBag.user = withEmailToUser;
        return View();
    }

my error: Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Cannot perform runtime binding on a null reference

CodePudding user response:

After deleting and recreating my view page, pasting the same codes fixed my problem.

  • Related