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
but I can't just do
public ActionResult View( int map.x, int map.y )
{
...
}
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?
You have to use use Model binder and set the prefix property to "map":
First create the Model object:
And in your action method:
You could make a class like this:
and then use that as a parameter for your action method
Try
IModelBinder
s. See this, this and this question.You can try an entirely different approach and build up your image map using the code provided in the following link.
http://www.avantprime.com/articles/view-article/9/asp.net-mvc-image-map-helper
To answer your question directly, you can change the field which is used on a parameter by using [Bind]:
However, a custom ModelBinder that bound an image map to a System.Drawing.Point struct would be nicer.
Edit: Here is an ImageMapBinder that automatically maps to a System.Drawing.Point argument. You don't have to decorate each Point argument with an attribute as long as you add the following code to your Application_Start:
Though you can still rename the input using
[Bind(Prefix="NotTheParameterName")]
if you want to.The code for ImageMapBinder is as follows: