c#
.net core razor ajax,.net core razor pages ajax 调用 c# 方法 -凯发ag旗舰厅登录网址下载
我目前正在制作一个网站来在谷歌地图上显示位置。我从 airtable.com 数据库中获取了位置地址,那里的一切都运行良好。然而,因为谷歌只允许一定数量的地理编码地址请求,我想将坐标保存在同一个数据库中,所以我只在需要查找新位置(地址)时才使用地理编码 api。我完成了所有设置,但我似乎无法弄清楚如何在剃刀页面中从 js 调用 cs 方法。我过去曾使用过 webmethod,但显然我不能在这里使用它。
当我尝试使用我在网上找到的示例时,它说我需要 requestverificationtoken,但这需要来自表单内的调用(我是对的吗?),并且在站点加载时会提示我的 ajax 调用并得到一个还没有任何坐标的数据库中的位置。
这是我第一次使用 razor pages,如果我完全误解了什么,请耐心等待。
我想调用的 cs 方法的图片 (index.cshtml.cs) 我尝试使用 httppost 标记,但没有任何区别
[httppost] // requestverificationtoken
public void onpostgeolocation()
{
// just to test that it actually gets called
console.writeline("onpostgeolocation called ####################################");
console.writeline("onpostgeolocation called ####################################");
console.writeline("onpostgeolocation called ####################################");
console.writeline("onpostgeolocation called ####################################");
}
来自 javascript 的 ajax 调用图片,基本上是在页面加载时调用:ajaxcall
function updaterow(recordid, latlng) {
console.log("rec_id: " recordid);
console.log("latlng: " latlng);
$.ajax({
type: "post",
url: '/index?onpostgeolocation',
contenttype: "application/json; charset=utf-8",
datatype: "json"
}).done(function (data) {
console.log(data.result);
})
}
我知道有些代码并不完全是我需要的,但我只是从网上复制,并会在我遇到这个障碍时进行编辑。
总结
以上是凯发ag旗舰厅登录网址下载为你收集整理的.net core razor ajax,.net core razor pages ajax 调用 c# 方法的全部内容,希望文章能够帮你解决所遇到的问题。
如果觉得凯发ag旗舰厅登录网址下载网站内容还不错,欢迎将凯发ag旗舰厅登录网址下载推荐给好友。
- 上一篇:
- 下一篇: