我认为这是一些愚蠢的问题,但仍然无法弄清楚。
我在 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>
当我尝试将值发送到 Controller 时(... new { id = buttonValue }),我收到此错误(“当前上下文中不存在名称“buttonValue””)。
任何对我有帮助的信息将不胜感激。
谢谢!
最佳答案
将 buttonValue
作为参数传递到 load
函数中:
$("#id").click(function () {
var buttonValue = $(this).val();
$("#modalBody").load("@Url.Action("Operation", "Controller")",
{ 'id': buttonValue });
});
关于javascript - MVC 4.0 的当前上下文中不存在名称 '<name>',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26675663/