views:

146

answers:

3

How do I catch the value of an image button in a controller. I have:

<input type="image" id="savebutton" name="savebutton" value="next" src="..." />

In my controller I have

    [AcceptVerbs(HttpVerbs.Post)]
    public ActionResult BillingShipping(string savebutton)
    {
        ...
    }

This works in Firefox but not in IE. However, if I change the button into a type="submit" it works fine.

Anyone please?

Thanks

A: 

An <input type="image" /> will send an x and y coordinate of where the user clicked on the image.

ZippyV
+1  A: 

In IE, an <input type="image"> includes only the coordinates when submitting the form, so the values you receive are, say, savebutton.x=100&savebutton.y=100. Firefox sends these values too, but also includes savebutton=next. IE does not.

If you just need to know that the image was clicked, the presence of the coordinates is enough. If you needed to know the value attribute, you're out of luck.

Since savebutton.x isn't a valid parameter name in C#, there are some handy suggestions of how to access those in your actions over here...
http://stackoverflow.com/questions/887648/asp-net-mvc-route-for-serverside-imagemap

stevemegson
Thanks. So it looks like in the case of multiple buttons in a form to stay away from input type="image". Hopefully css will let me make a input type="submit" with a background image that will look the same.
Thomas
A: 

A more general solution to a bit more general problem is here

naugtur