需要一些帮助排序错误添加了代码截图和代码返回的错误。尝试从 Jquery 调用 C# 函数并传递参数。
_主持人
function getElementSVG(e) {
var position = getPosition(e);
var circle = makeSVG('circle', { cx: position.pointx, cy: position.pointy, r: 0.02, stroke: 'black', 'stroke-width': 0.5, fill: 'black' });
document.getElementById(e.currentTarget.id).appendChild(circle);
DotNet.invokeMethodAsync('PeopleCounterWeb', 'AddPointToList', position.pointx, position.pointy).then(result => {
console.log(result);
});
return position;
}
function fnsuccesscallback(data) {
alert(data.d);
}
function fnerrorcallback(result) {
alert(result.statusText);
}
function makeSVG(tag, attrs) {
var el = document.createElementNS('http://www.w3.org/2000/svg', tag);
for (var k in attrs)
el.setAttribute(k, attrs[k]);
return el;
}
function getPosition(e) {
var rect = e.target.getBoundingClientRect();
var x = e.clientX - rect.left;
var y = e.clientY - rect.top;
var width = rect.width;
var height = rect.height;
var pointx = ((x / width) * 100).toFixed(2);
var pointy = ((y / height) * 100).toFixed(2);
return {
pointx,
pointy
}
};
MainMap.cshtml
[JSInvokable]
public string AddPointToList(string x, string y)
{
var alpha = x + "-" + y;
return "";
//Points.Add(obj[0], obj[1]);
}