如何在MVC4中精准地捕获x和y位置并重新定位?

8 浏览
0 Comments

如何在MVC4中精准地捕获x和y位置并重新定位?

这个问题已经有了答案

可能的重复:

动态检索HTML元素的位置(X,Y)

在一个MVC4应用程序(目标为IE7 +)中,我有一张图片。我希望用户能够点击图片放置一个小标记(图片),并且我希望存储与图像相关的相对x / y位置,以便当用户再次返回该页面时重新定位此引脚。

如何完成这个任务最好的方法是什么?

admin 更改状态以发布 2023年5月24日
0
0 Comments

你可以使用一个标签 - 它的行为类似于,但会将点击的x和y坐标回传到服务器。

View

Click on the image to place a pin

@using(Html.BeginForm()) { }

Controller

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }
    [HttpPost]
    public ActionResult Index(FormCollection form)
    {
        int x = int.Parse(form["coords.x"]);
        int y = int.Parse(form["coords.y"]);
        // FIXME Save location of pin
        return View();
    }
}

0