简体   繁体   English

从asp.net中的另一个页面重定向到特定选项卡

[英]Redirect to specific tab from another page in asp.net

Good day all, I'm using Bootstrap 3 in asp.net mvc 4 & I'm trying to make tabs with bootstrap. 一切顺利,我在asp.net mvc 4中使用Bootstrap 3,并且尝试使用bootstrap创建选项卡。 I want other pages to redirect to a specific tab when clicked. 我希望其他页面在单击时重定向到特定选项卡。 I'm new to asp.net so I can't figure it out how can I do that. 我是asp.net的新手,所以我不知道该怎么办。 Here is my code, 这是我的代码,

Page that has the tabs(Service_BO.cshtml) 带有标签的页面(Service_BO.cshtml)

<div class="container well" style="min-width: 100%; padding-right: 5px;">
    <h3>BO Account Opening</h3><hr style="border-top: 2px solid #096596;" />
    <ul class="nav nav-tabs">
        <li><a href="#bo" role="tab" data-toggle="tab">BO Account Opening</a></li>
        <li><a href="#ipo" role="tab" data-toggle="tab">IPO Application</a></li>
        <li><a href="#smi" role="tab" data-toggle="tab">Share Market Investment</a></li>
    </ul>
    <div class="tab-content">
        <div class="tab-pane active" id="bo">
            <p>BO</p>
        </div>
        <div class="tab-pane" id="ipo">
            <p>IPO</p>
        </div>
        <div class="tab-pane" id="smi">
            <p>SMI</p>
        </div>
    </div>
</div>

External Page(Services.cshtml> 外部页面(Services.cshtml>

<div class="col-sm-6 col-md-3">
    <img class="img-rounded img-responsive" src="~/Images/modhumita01.jpg" />
    <a href="@Url.Action("Service_BO", "Home")><h3>BO Account Opening</h3></a>
    <span><b>Open an individual and/or joint account</b></span>
</div>

Is there any way I can redirect to a specific tab by clicking a link from other page? 我可以通过单击其他页面上的链接来重定向到特定选项卡吗? It'll be a life saving if anyone can help me. 如果有人可以帮助我,将挽救生命。 Tnx. Tnx。

You can resolve the active tab in your controller and pass the value to view (in your ViewModel, or ViewBag). 您可以解析控制器中的活动选项卡,并将值传递给视图(在ViewModel或ViewBag中)。 Then you can use jquery to set the active class: 然后,您可以使用jquery设置活动类:

Controller 控制者

//empty value or a default
var activeTab = "bo";

//selecting active tab logic here
//...
ViewBag.Active = activeTab;

Service_BO.cshtml Service_BO.cshtml

@{
    //value is 'bo', 'ipo' or 'smi'
    string active = ViewBag.Active.ToString(); 
}

<script>
$(function () {
    var selector = '@active';
    $("#" + selector).addClass("active");
});
</script>

Can do something like this based on link shown above in comments 可以根据上面注释中显示的链接执行类似的操作

/* page load */
$(function(){
  var hash = window.location.hash;
  hash && $('ul.nav a[href="' + hash + '"]').tab('show');  


  /* add hash to url when tabs selected (for bookmarking) */
  $('.nav-tabs a').on('shown', function (e) {
      window.location.hash = this.hash;
  });
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM