使用java脚本变量
问题描述:
我有一个文本框,在那里我必须写一个价值,如何在我的控制器,如果我打电话用的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派蒂什 感谢
答
而不是使用一个动作环节,使用标准的链接:
<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
。
答
这是正确的脚本:
$("#l").attr("href", "@Url.Action("ApplyCommand", "Work")?tisch=" + tisch);
传递的值是空 – 2012-08-14 13:20:29
对象[对象的对象]无方法“href”属性 – 2012-08-14 13:37:18
哦对不起,上述更新。 – 2012-08-14 14:14:56