【发布时间】:2017-10-03 02:29:54
【问题描述】:
在我的 ASP 应用程序中,我试图从数据库中检索一个值。从 javascript 我尝试执行控制器方法。
Javascript
function getCapital(country) {
//alert(country);
var url = "~/Home/Capital";
$.get(url, { country: country }, function (response) {
$("#getCapital").html(response);
alert(response);
});
控制器(家庭)
public string Capital(string country)
{
return capitalService.getCapital("Frankrijk");
}
但我没有得到任何结果。
编辑
查看
<script type="text/javascript" src="/Scripts/jquery-1.4.1.js"></script>
<script type="text/javascript" src="/Scripts/World.js" ></script>
这是浏览器控制台的输出。所以有时它会记录 URL 而不会出错。
【问题讨论】:
-
public ActionResult Capital(string country) { return capitalService.getCapital("Frankrijk"); }
-
@DaveClough 我无法在 ActionResult 方法中返回类型字符串。
-
可以,ActionResult 会包装字符串
标签: javascript asp.net model-view-controller controller