I would like to set a ViewBag variable (flag) to determine which partial view to show in my shared layout view. The partials are a set of icons. When the "more" icon is clicked I want to swap in a different partial with a different set of menu icons. the "more" icon click code is set in the layout javascript:
$(function () {
$('#moreIcon').click(function () {
$.ajax({
url: 'Home/LoadMoreIcons',
dataType: "html",
success: function (data) {
}
});
});
});
The controller action is:
public EmptyResult LoadMoreIcons()
{
ViewBag.arrowClick = true;
return null;
}
The _layout view (razor) code is:
<div id="headIcons">
@if ((bool?)ViewBag.arrowClick == false)
{
@Html.Partial("mainIconsPartial")
}
else
{
@Html.Partial("moreIconsPartial")
}
</div>
Whats happening is that the "else" logic never happens even though I can break at the point where the Viewbag variable is getting set in the controller action when the "more" icon is clicked.
(bool?)ViewBag.arrowClick
evaluate to? What about@if (true)
? – Cheezmeister