I'm having an issue where after logging out, I redirect to my site's login page. However, the login page's javascript is not executing at all unless I refresh.
I'm using the following link to call the LogOff action of the Account controller (this code is in a separate controller):
@Html.ActionLink("Logout", "LogOff", "Account", null, new { data_icon = "gear", @class = "ui-btn-right" })
The LogOff method in the Account controller looks like this, where I pass a logout parameter in order to detect in the Login view that I came here from a logout action:
public ActionResult LogOff()
{
return Redirect(Url.Action("LogOn", "Account", new RouteValueDictionary(new { logout = true })));
}
Checking in firebug, I noticed that the javascript
$(document).ready(function () { ... });
used in my login page doesn't execute at all.
Furthermore, the login page's url reads "localhost:#####/Account/LogOff" rather than the "localhost:#####/Account/LogOn?logout=True" which I would have expected.
If I try to submit the login form afterwards, then I'm sent to a blank page with the url "http://localhost:#####/?logout=True"
So I would like to know what I'm doing wrong that is preventing the page from loading with its javascript, and how I can fix the issue.
Thanks!
Update: Here is my LogOn controller method:
public ActionResult LogOn()
{
List<SelectListItem> cpList = new List<SelectListItem>();
// Retrieve the list of central points from web.config
NameValueCollection centralPoints = (NameValueCollection)ConfigurationManager.GetSection("CentralPointDictionary");
foreach (string cp in centralPoints)
cpList.Add(new SelectListItem { Text = cp as string, Value = centralPoints[cp] as string });
// Check for a cookie containing a previously used central point
string selectedCP = string.Empty;
if (ControllerContext.HttpContext.Request.Cookies["LastCentralPoint"] != null)
selectedCP = ControllerContext.HttpContext.Request.Cookies["LastCentralPoint"].Value;
else if (cpList.Count > 0)
selectedCP = cpList[0].Text;
LogOnModel loginModel = new LogOnModel { CentralPointsList = new SelectList(cpList, "Value", "Text", selectedCP) };
return View(loginModel);
}
And the body of my View:
<div data-role="page" id="page">
<div data-role="header" data-position="inline">
<div id="languageContainer" data-role="fieldcontain">
<select id="languageSelect" data-mini="true" data-theme="b" data-overlay-theme="d" data-native-menu="false" data-inline="true">
<option value="English">English</option>
<option value="Français">Français</option>
</select>
</div>
</div><!-- /header -->
<div data-role="content" id="contentFrame" class="frame">
<div id="controlFrame">
@using (Html.BeginForm())
{
<div id="centralPoint" class="frame">
@Html.DropDownListFor(model => model.CentralPointAddress, Model.CentralPointsList, new { id = "centralPointSelect", name = "centralPoint", data_mini = "true", data_inline = "true", data_native_menu = "false" })
</div>
<div id="errorMsg">@Html.ValidationSummary()</div>
<div id="credentialsFrame" class="frame">
@Html.TextBoxFor(m => m.UserName, new { id = "userField", type = "text", name = "Username" })
@Html.PasswordFor(m => m.Password, new { id = "passField", type = "password", name = "Password" })
</div>
<input id="loginBtn" type="submit" value="Login" />
<div id="rememberMe" class="frame">
@Html.CheckBoxFor(m => m.RememberMe, new { @class = "custom", data_mini = "true" })
@Html.LabelFor(m => m.RememberMe)
</div>
<div id="forgotPassFrame">
<input id="forgotPass" type="button" data-mini="true" value="Forgot password?" />
</div>
@Html.HiddenFor(m => m.Encrypted, new { id = "encrypted", value = "false" })
}
</div>
@using (Html.BeginForm("SuccessfulLogin", "Account", FormMethod.Get, new { id = "successForm" }))
{
<input id="returnUrl" name="returnUrl" type="hidden" />
}
</div><!-- /content -->
</div><!-- /page -->