I am using Bootstrap and have Tabs that are created dynamically. Although they are dynamic, I will only create 3 Tabs. They are: Draft, Published and Archived. These are actually Enums.
When I click on a tab, I want to change a hidden field to the same value of the tab so that when Postback occurs, I wish to open the selected that was previously opened.
The tabs id is #i where i is the iterator within the for loop. So the Tabs will be: #0, #1 and #2.
Does anyone know how I can create one onclick event for all the tabs and make the hidden field's value change to that of the Tabs id.
This is the the code:
<div class="tab-content">
@for (int i = 0; i < Model.WorkflowStatuses.Count; i++)
{
<div class="tab-pane @(i == 0 ? "active" : string.Empty)" id="@i">
編集 これは私がこれまでに持っているものです-非表示フィールドの値は変更されていません:
<script>
$('#listingTab a[data-toggle="tab"]').on('show', function (e) {
$('#selectedTab').val($(e.target).prop('id'));
})
@Html.HiddenFor(m=>Model.SelectedTab)
@if (Model.AnyListings)
{
<ul class="nav nav-tabs" id="listingTab">
@for (int i = 0; i < Model.WorkflowStatuses.Count; i++)
編集 文字「t」を追加しましたが、非表示の値はまだ変更されていません:
<script>
$('#tab-content a[data-toggle="tab"]').on('show', function (e) {
$('#SelectedTab').val($(e.target).prop('id'));
})
</script>
@Html.HiddenFor(m=>Model.SelectedTab)
@if (Model.AnyListings)
{
<ul class="nav nav-tabs" id="listingTab">
@for (int i = 0; i < Model.WorkflowStatuses.Count; i++)
{
<li class="@(i == 0 ? "active" : string.Empty)"><a href="@string.Format("#t{0}", i)" data-toggle="tab">@Model.WorkflowStatuses[i].ToString()</a></li>
}