2012-08-14 66 views
0

我有一個文本框,在那裏我必須寫一個價值,如何在我的控制器,如果我打電話用的ActionLink我的控制器通過這個值,這是我的代碼:使用java腳本變量

觀點:

@Html.TextBox("tisch", "", new { @class = "teschChange"}) 
@Html.ActionLink("Apply Command", "ApplyCommand", "Work") 

,這是德腳本

<script type="text/javascript"> 
    $(function test() { 
     $(".teschChange").change(function() { 
      var tisch = $(this).attr('value'); 
     }); 
    }); 
</script> 

我一定要在ApplyCommandController派蒂什 感謝

回答

1

而不是使用一個動作環節,使用標準的鏈接:

<a id="l" href="@Url.Action("ApplyCommand", "Work")">Apply Command</a> 

然後,你可以使用這個腳本:

<script type="text/javascript"> 
    $(function test() { 
     $(".teschChange").change(function() { 
      var tisch = $(this).attr('value'); 
      $("#l").attr("href", "@Url.Action("ApplyCommand", "Work")/" + tisch); 
     }); 
    }); 
</script> 

這將分配的A HREF:/Work/ApplyCommand/tisch

+0

傳遞的值是空 – 2012-08-14 13:20:29

+0

對象[對象的對象]無方法「href」屬性 – 2012-08-14 13:37:18

+0

哦對不起,上述更新。 – 2012-08-14 14:14:56

0

這是正確的腳本:

$("#l").attr("href", "@Url.Action("ApplyCommand", "Work")?tisch=" + tisch);