【问题标题】:how to show selected option in MVC asp.net如何在 MVC asp.net 中显示选定的选项
【发布时间】:2016-08-29 10:34:34
【问题描述】:

我有这个代码:

<div class="navbar-collapse collapse">
    <ul class="nav navbar-nav">
        <li class="dropdown">
            <a id="na" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Environments <span class="caret"></span></a>
            <ul class="dropdown-menu">
                <li>@Html.ActionLink("Reports - ", "Index", "Reports", new { environment = "" }, null)</li>
                <li>@Html.ActionLink("Reports - ", "Index", "Reports", new {environment = "" }, null)</li>
                <li>@Html.ActionLink("Reports - ", "Index", "Reports", new { environment = "" }, null)</li>
                // <li>@Html.ActionLink("Reports - ", "Index", "Reports", new { environment = "" }, null)</li>
            </ul>

`

我想知道如何显示用户在渲染 html 上按下的选定选项

【问题讨论】:

    标签: javascript jquery asp.net-mvc c#-4.0


    【解决方案1】:

    使用下面的代码:

            $(function(){
    
            $(".dropdown-menu").on('click', 'li a', function(){
    console.log($(this).text());
           });
    
        });
    

    【讨论】:

      【解决方案2】:

      根据我从您的问题中了解到的情况,您想显示或知道从这 3 个 li 中单击了哪个 Actionlink 或超链接? 如果是,那么您可以在视图中发送一些路由值

       <div class="navbar-collapse collapse">
              <ul class="nav navbar-nav">
                  <li class="dropdown">
                      <a id="na" href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Environments <span class="caret"></span></a>
                      <ul class="dropdown-menu">
                          <li>@Html.ActionLink("Reports - ", "Index", "Reports", new { environment = "1" }, null)</li>
                          <li>@Html.ActionLink("Reports - ", "Index", "Reports", new {environment = "2" }, null)</li>
                          <li>@Html.ActionLink("Reports - ", "Index", "Reports", new { environment = "3" }, null)</li>
                          // <li>@Html.ActionLink("Reports - ", "Index", "Reports", new { environment = "" },null)</li>
                      </ul>
      

      然后在你的报表控制器控制器中

      public ActionResult Index(string environment)
      {
        string ClickValue = environment; //You get use Clickvalue here
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-03-01
        • 2011-02-15
        • 2012-05-06
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多