0
votes

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.

1
What does (bool?)ViewBag.arrowClick evaluate to? What about @if (true)?Cheezmeister
not sure what you mean. How can I tell what it evaluates to?MikeD
sorry - it was false... dumb mistake ... set the var to false in the Index action and forgot it. Overrid my previous set.MikeD

1 Answers

0
votes

my bad ... missed a set of the Viewbag variable I previously set.