How To in EJ 1 ASP.NET MVC Tab

28 Feb 2019 / 1 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>);

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