How To

28 Feb 20191 minute to read

Add a tab item dynamically based on condition

To add tab item dynamically based on condition, we can use the conditional operators to check and add the items within the items property. Refer to the following code.

@{Html.EJ().Tab("defaultTabs").Items(data =>
        {
            data.Add().ID("reviews").Text("Reviews").ContentTemplate(@<div>@{ Html.RenderPartial("_ReviewList"); }</div>);
            if (user == "admin") { // check the condition to load the item in tab
                    data.Add().ID("calendar").Text("Calendar").ContentTemplate(@<div> @{ Html.RenderPartial("_Calendar"); }</div>);
            }
        }).ShowRoundedCorner(true).Render();}

In the above code, based on the “user” the second tab will be displayed.

Sample