Before the page loads, I need to run a check on the user's security level. This will determine which elements of our nav bar they are able to see. I have tried two methods at running this ajax call, both inside the $(document).ready
function.
(the div
named container
encompasses the ul
in the html below)
$(document).ready(function ($) {
//First attempt
$('#container').load(
$.ajax({
type: 'GET',
url: '@Url.Action("CheckSecurity","Home")'
})
);
//Second attempt
window.onload = function () {
$.ajax({
type: 'GET',
url: '@Url.Action("CheckSecurity","Home")'
});
};
});
Since this is an ASP MVC 3 site, I've set a breakpoint in the CheckSecurity
method. I can tell neither call is working due to the fact it is never fired.
The controller method is listed below
public ActionResult CheckSecurity()
{
ViewBag.UserName = Security.GetUserName(User);
ViewBag.Admin = Security.IsAdmin(User);
ViewBag.ITsupport = Security.IsItSupport(User);
ViewBag.Read = Security.IsViewer(User);
ViewBag.Modify = Security.IsModifier(User);
return View();
}
This is supposed to check the user's security level, place the boolean
value in the ViewBag, and then determine whether or not to display the Admin Features
drop down item below
<li class="dropdown">
<a href="#"
class="dropdown-toggle"
data-toggle="dropdown"
data-hover="dropdown">
Admin
<b class="caret"></b>
</a>
<ul class="dropdown-menu">
<li>@Html.MenuLink("Products", "Index", "Product")</li>
<li>@Html.MenuLink("Product Training", "Index", "Course")</li>
<li>@Html.MenuLink("Continuing Ed", "Index", "ContEdCourse")</li>
@if (ViewBag.Admin)
{
<li>@Html.MenuLink("Admin Features", "Index", "DropDownValues")</li>
}
</ul>
</li>
When the page attempts to load, it instead crashes with this error pointing to the @if (ViewBag.Admin)
line:
Cannot convert null to 'bool' because it is a non-nullable value type
Any help/suggestions greatly appreciated. Thx!