对于服务器端的图像映射ASP.NET MVC路线 [英] ASP.NET MVC route for serverside imagemap

查看:103
本文介绍了对于服务器端的图像映射ASP.NET MVC路线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个<输入类型=形象> 在ASP.NET MVC的观点,但我不知道如何检索坐标在动作表单提交时运行。所请求的URL看起来像

I've got an <input type='image'> in an ASP.NET MVC view, but I'm not sure how to retrieve the coordinates in the action that runs when the form is submitted. The requested URL looks like

/Map/View/?map.x=156&map.y=196

但我不能只是做

public ActionResult View( int map.x, int map.y )
{
  ...
}

因为他们显然不适合C#方法参数的有效名称。有没有在 ActionName 属性的任何等同于查询参数映射到方法参数?

because they're obviously not valid names for C# method parameters. Is there any equivalent of the ActionName attribute to map query parameters to method parameters?

推荐答案

您必须使用使用模型绑定,并设置preFIX属性地图:

You have to use use Model binder and set the prefix property to "map":

首先创建Model对象:

First create the Model object:

public class ImageMap()
{
  public int x{get;set;}
  public int y{get;set;}
}

而在你的操作方法:

And in your action method:

public ActionResult About([Bind(Prefix="map")]ImageMap map)
{

   // do whatever you want here
    var xCord = map.x;

}

这篇关于对于服务器端的图像映射ASP.NET MVC路线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆