1

Note: I am new to jQuery and tabs.

I am attempting to implement nested tabs with jQuery tabs in an MVC 5 web application. For some reason, the implementation is not working correctly and I assume there is a bug based on the behavior on the website and I suspect it is with how the active tab is being set.

When the user logs in, they are taken to a page for MainAppTabs. The two top tabs are Client and Account. The Client tab has nested tabs Client Info, Billing Selections, and About whereas the Account tab currently has only one nested tab called Account, which should only display a list of accounts.

With the current implementation below, the Account tab is the first tab to be displayed, as opposed to the Client tab, along with the nested Account tab. When I click on the Client tab then it will display fine with its nested tabs. However, when I click on the Account tab again then the page clears out and I must refresh the page (F5) in order to get the Account tab and its nested tabs to display. Also, the nested tab appears to be displayed twice where it is offset to the right and has a duplicate border, but the nested tab border and data spill outside of the parent tab border.

<div id="MainAppTabs">
    <ul>
        <li>@Html.ActionLink("Client", "ClientTabs", "ClientSetup")</li>
        <li>@Html.ActionLink("Account", "AccountTabs", "AccountSetup")</li>
    </ul>
</div>

<script>
    $(function () {
        $("#MainAppTabs").tabs({ active: 1 });
    });
</script>

ClientTabs:

<div id="ClientSetupTabs">
    <ul>
        <li>@Html.ActionLink("Client Info", "Edit", "ClientSetup")</li>
        <li>@Html.ActionLink("Billing Selections", "BillingSelections", "ClientSetup")</li>     
    </ul>
</div>

<script>
    $(function ()
    {
        $("#ClientSetupTabs").tabs({ active: 1 });
    });
</script>

AccountTabs:

<div id="AccountSetupTabs">
    <ul>
        <li class="active">@Html.ActionLink("Accounts", "Index", "AccountSetup")</li>
    </ul>
</div>

<script>
    $(function ()
    {
        $("#AccountSetupTabs").tabs({ active: 1 });
    });
</script>
Abhilash Ravindran C K
  • 1,818
  • 2
  • 13
  • 22
J Weezy
  • 3,507
  • 3
  • 32
  • 88
  • That is not the normal way of defining the html for tabs. Typically you have a link with `
  • Client
  • ` and then a `
    @Html.Partial(...)
    ` (or `@Html.Action(...)`) as the placeholder for the content. –  Mar 19 '18 at 07:21
  • The href attribute of "a" element and id of the div must be equal in order to display tabs properly. – MonkeyDLuffy Mar 19 '18 at 14:08
  • @Stephen, are partial views required for nested tabs only or for all tabs? Do you have any examples or documentation that I can read on the subject? – J Weezy Mar 19 '18 at 14:56
  • @Monkey, I am not sure I understand what you mean. Can you please provide a code example? Is it possible to do this with the Razor Views engine? – J Weezy Mar 19 '18 at 14:56
  • Refer [this fiddle](https://jsfiddle.net/y7m3zksw/11/) for how you view needs to be set up. Just eplace the "content for ...." with `@Html.Partial()` or `@Html.Action()` to render the content. –  Mar 19 '18 at 23:27
  • And as a side note, never put scripts in partials –  Mar 19 '18 at 23:28
  • @Stephen. The Fiddle that you provided is what I was looking for. Please post it as the answer so I can give you credit for it. Thank you very much. – J Weezy Mar 20 '18 at 06:00
  • Sure, Give me an hour or so. –  Mar 20 '18 at 06:02