我有我认为这是一个愚蠢的问题,但仍然无法弄明白。
我在MVC 4.0 Web应用程序中遇到了一些HTML问题。这是代码:
<button class="btn btn-primary" value=@item.ID id="id" data-toggle="modal" data-target="#myModal">Do something</button>
<script type="text/javascript" charset="utf-8">
$(function (e) {
$("#id").click(function () {
var buttonValue = $(this).val();
$("#modalBody").load("@Url.Action("Operation", "Controller", new { id = buttonValue })");
});
});
</script>
当我尝试将值发送到控制器时,我收到此错误(&#34;名称&#39; buttonValue&#39;在当前上下文&#34;中不存在)(.. .new {id = buttonValue})。
非常感谢任何帮助我的信息。
谢谢!
答案 0 :(得分:1)
将buttonValue
作为参数传递到load
函数:
$("#id").click(function () {
var buttonValue = $(this).val();
$("#modalBody").load("@Url.Action("Operation", "Controller")",
{ 'id': buttonValue });
});