如何在MVC asp.net中显示所选选项

时间:2016-08-29 10:34:34

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

我有这段代码:

<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上按下的选定选项

2 个答案:

答案 0 :(得分:0)

使用以下代码:

        $(function(){

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

    });

答案 1 :(得分:0)

从您的问题中我可以理解您要显示或知道从这些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
}