Tabs - Return to desired tab

Asked

Viewed 36 times

0

Good morning, you guys! In my Suppliers register, in View Details, I have a Tab with the tabs: Data, Contacts and Purchases, and when I click on the Contacts tab, there is a button to register a new contact and directs me to the Suppliers Contact View. When registering the new contact, I need to return to the Suppliers' View Details, but in the Contacts tab. My Suppliers View Details tab looks like this:

<ul class="nav nav-tabs" id="myTab" role="tablist">
    <li class="nav-item">
        <a class="nav-link active" id="home-dados" data-toggle="tab" href="#dados" role="tab" aria-controls="dados" aria-selected="true">Dados</a>
    </li>
    <li class="nav-item">
        <a class="nav-link" id="contatos-tab" data-toggle="tab" href="#contatos" role="tab" aria-controls="contatos" aria-selected="false">Contatos</a>
    </li>
    <li class="nav-item">
        <a class="nav-link" id="compras-tab" data-toggle="tab" href="#compras" role="tab" aria-controls="compras" aria-selected="false">Compras</a>
    </li>
</ul>

<div class="tab-content" id="myTabContent">
    <div class="tab-pane fade show active" id="dados" role="tabpanel" aria-labelledby="dados-tab">Exibe os dados do Fornecedor</div>
    <div class="tab-pane fade" id="contatos" role="tabpanel" aria-labelledby="contatos-tab">
        <table class="table table-bordered" >
            <tr>
                <th>Tipo do contato</th>
                <th>Descrição</th>
            </tr>
            <tr>
                <td>Telefone</td>
                <td>9999-8888</td>
            </tr>
            <tr>
                <td>Email</td>
                <td>oxoxoxoxo.com.br</td>
            </tr>
        </table>
        <br />
        <button type="button"
                title="Novo registro"
                class="btn"
                style="background-color: lightsteelblue;"
                onclick="location.href='@Url.Action("Create", "ContatoFornecedores", new { FornecedorId = @TempData["FornecedorId"] })'">
            Novo Contato
        </button>
    </div>
    <div class="tab-pane fade" id="compras" role="tabpanel" aria-labelledby="compras-tab">Exibe todas as compras efetuadas junto ao Fornecedor</div>
</div>

What a way to do it?

1 answer

0

I thought I’d put one more parameter in onclick, so:

onclick="window.location.href='@Url.Action("Details", "Fornecedores", new { id = @TempData["FornecedorId"], selectTab = 2})'">

Then, when you return to Vendor View Details, the url looks like this:

http://localhost:61801/Vendors/Details/9? selectTab=1

Now I needed a way to take this selectedTab in the Controller and send it to the View to open the tab I want. I thought I’d do it like this:

public ActionResult Details(int? id, int? selectedTab)
{
    if (selectedTab == null)
    {
       TempData["SelectedTab"] = 0;
    }
    else
    {
       TempData["SelectedTab"] = selectedTab;
    }
    return View();
}

Am I going the right way? Someone could give me a light?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.