In Asp.Net Core MVC web application,
How to keep selected tab Active upon redirect to Controllers Index action
I am developing tabs UI, using below code:
<div class="col-md-12">
<div class="collDiv">
<ul class="nav nav-tabs nav-justified" id="myTab" role="tablist">
<li class="nav-item active">
<a class="nav-link" asp-area="" asp-controller="MappingStudy" asp-action="Index">Mapping Study/Scenario/Project</a>
</li>
<li class="nav-item">
<a class="nav-link" asp-area="" asp-controller="MappingWell" asp-action="Index">Mapping Wells</a>
</li>
<li class="nav-item">
<a class="nav-link" asp-area="" asp-controller="MappingCost" asp-action="Index">Mapping Costs</a>
</li>
<li class="nav-item">
<a class="nav-link" asp-area="" asp-controller="MappingProduction" asp-action="Index">Mapping Production</a>
</li>
</ul>
</div>
</div>
@section Scripts {
<script type="text/javascript">
@*$(function () {
$('ul li a').each(function () {
$('#' + '@ViewBag.Title').addClass('active');
});
});*@
$('li a').click(function () {
//$('li a').removeClass("active");
//$(this).addClass("active");
var current = document.getElementsByClassName("active");
current[0].className = current[0].className.replace(" active", "");
this.className += " active";
});
</script>
}
Above Javascript doesn't work as expected. I tried 2-3 ways but nothing works as expected.
Requirement: When I click on any Tab, page redirects to particular controller's Index action and selected tab shall remain active.
Issue: when I click on any tab, the tab is active for few seconds until page is redirected to Index action. After redirect, active no longer works.
Please let me know how to keep selected tab Active upon redirect to Index action.
Thank you in advance.