[英]Controller Method in MVC not called
I got quite a simple JS-Method: 我得到了一个非常简单的JS方法:
<script language="javascript">
function AmountChanged(callingTextbox) {
var enteredQuantity = callingTextbox.value;
$.getJSON("/Catalog/GetEnteredQuantity",
{
id: enteredQuantity
},
function (data) {
alert(data.MoneyText);
});
}
</script>
This "should" call a function in my Controller: 这“应该”在我的控制器中调用一个函数:
public partial class CatalogController : BaseController {
[HttpPost]
public JsonResult GetEnteredQuantity(object id)
{
var result = new { MoneyText = "kost nix" };
return Json(result);
}
}
Through Chrome I can see that the JavaScript function is called. 通过Chrome,我可以看到JavaScript函数已被调用。 The debugger steps through until the line
$.getJSON("/Catalog/GetEnteredQuantity",
and then jumps to the last closing bracket of that JS-Function. But the GetEnteredQuantity()-Method is never called. 调试器逐步执行直到
$.getJSON("/Catalog/GetEnteredQuantity",
然后跳转到该JS函数的最后一个$.getJSON("/Catalog/GetEnteredQuantity",
括号,但从未调用GetEnteredQuantity()-Method。
The console shows a "http://localhost:2451/Catalog/GetEnteredQuantity?id=48 404 Not Found"
控制台显示
"http://localhost:2451/Catalog/GetEnteredQuantity?id=48 404 Not Found"
What is wrong here? 怎么了
Remove the HttpPost attribute from the action 从操作中删除HttpPost属性
public partial class CatalogController : BaseController {
[HttpPost] //Remove it
public JsonResult GetEnteredQuantity(object id)
{
var result = new { MoneyText = "kost nix" };
return Json(result);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.