1

基本上我的目标是使用 JQuery 将 x & y 鼠标坐标回传到我的控制器,其中 2 个值被添加到数组/列表中,然后添加到会话中。

在构建一个包含每个坐标的 XML 字符串之前,我想遍历一系列 60 次单击(以及随后回发到控制器)。

类似这样的东西:

<xml>
<click1>
 <xpos>45</xpos>
 <ypos>55</ypos>
</click1>
<click2>
 <xpos>45</xpos>
 <ypos>55</ypos>
</click2>
</xml>

我不确定在每次回发后如何最好地存储单个鼠标点击,我认为会话和多维数组/列表可能对此有好处?对于如何将会话转换回列表并根据需要组装 XML,我也有点困惑。

谁能指出我正确的方向?

非常感谢!

赛克斯。

4

1 回答 1

1

我通过创建一个类型的 Dictionary 来解决这个问题,其中 MouseCoordinates 指的是一个接受 xposition 和 yposition 的 2 个字符串值的类。

然后,我将 Dictionary 放入一个会话中,当我需要为其添加新值时,将其重新转换为 Dict。

最后,在检索所有值的点击周期结束时,我遍历了字典。

我希望这段代码可以帮助某人:

var coords = new Dictionary<int, MouseCoordinates>();

HttpContext.Session.Add("coords", coords);

// Accessing Dictionary From Session
var coords = (Dictionary<int, MouseCoordinates>)HttpContext.Session["coords"];

// Adding Values using a integer stage that's posted back to the controller
coords.Add(currentStage, new MouseCoordinates { xposition = xpos, yposition = ypos });

// Looping through the session at the end of the cycle
            foreach (var ords in coords)
            {
                var qnode = ords.Key;
                var xvalue = ords.Value.xposition;
                var yvalue = ords.Value.yposition;
            }
于 2012-06-15T14:25:11.240 回答