繁体   English   中英

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

[英]how to show selected option in MVC asp.net

我有以下代码:

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

使用以下代码:

        $(function(){

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

    });

从我从您的问题中可以理解的是,您要显示还是要知道从那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
}

暂无
暂无

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

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