When you hit the index page it checks to see whether or not you are logged in:

public ActionResult Index()
        {
            if (Session["UserName"] == null)
            {
                return View();
            }
            else
            {
                return RedirectToAction("MyReservations", "Home");
            }

        }

If you are logged in this goes into the else block and it successfully redirects the browser to the new route and the new view loads.

If you are not logged in and you log in:

[HttpPost]
    public void ButtonClick(string employeeID)
        //When the user is created a userName 
        //is assigned
        User newuser = new User(employeeID);
        if (newuser.userName != String.Empty)
        {
            Session["UserName"] = newuser.userName;
        }

The JS function that called this method reloads the page on success:

$("#btn_login").click(function () {
        var employee_id = $("#txtID").val();
        $.ajax({
            url: "/Home/ButtonClick",
            type: "POST",
            data: { 'employeeID': employee_id.toString() },
            success: function () {
                location.reload();
            }
        })
    })

When I go to the index page manually after login it redirects me to the new route and the view renders.

When the JavaScript tries to reload the index page after login it redirects me to the new route but the body of the view does not render (but the source of the html document shows the body is there).

What causes the different results and is there a way to make the page load properly when the JavaScript reloads it?

Related posts

Recent Viewed