ASP.Net MVC的ActionLink [英] ASP.Net MVC ActionLink

查看:85
本文介绍了ASP.Net MVC的ActionLink的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的观点,一个下拉列表中选定的值发送到一个新的动作之一创建ActionLink的。到目前为止,我有这个,我只需要找到一种方法来填充我的ActionLink的末端的ID。

I'm trying to create an ActionLink in one of my views that sends the selected value of a dropdown list to a new action. So far I have this, I just need to find a way to populate the ID on the end of my ActionLink.

   <%= Html.DropDownList("StatusDropDown") %>
   <%= Html.ActionLink("Apply","Index",new {Controller="Tasks", Action="Index", id="DROPDOWN LIST SECLECTED VALUE"}) %>

显然,这链接需要被更新时下降的所选索引向下被改变。这是不是我需要在JavaScript中做的或者是有ASP.Net MVC?

Obviously this link would need to be updated whenever the selected index of the drop down is changed. Is this something I need to do in javascript or is there a better way of managing this from within ASP.Net MVC?

感谢

推荐答案

如果你不希望使用表单提交(即,要作为链接,而不是形式参数的一部分传递的参数),则需要使用JavaScript来构建URL的客户端。

If you don't want to use form submission (i.e., want the parameter passed as part of the url instead of a form parameter), you'll need to build the url client-side with javascript.

<%= Html.DropDownList("StatusDropDown") %>
<a id="applyLink" href="#">Apply</a>

<script type="text/javascript">

    function setHref( elem, val )
    {
        if (val) {
           $(elem).attr( "href", "/Tasks/" + val );
           $("#applyLink").unbind("click");
        }
        else {
           $(elem).attr( "href", "#" );
           $("#applyLink").click( function() { alert( "No value chosen" ); } );
        }
    }

    $(function() {
       var dropdown = $("#StatusDropDown");
       dropdown.change( function() {
           setHref( this, $(this).val() );
       });
       setHref( dropdown, null );
    });
</script>

这篇关于ASP.Net MVC的ActionLink的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆