Question

I have an image in a view

<input type="image" src="(Location)" name="next" id="imgNext"/>

Now what I need to do is to pass the name of the image ("Next") to the action method in the controller, when a user clicks the image...which causes a Post request to the action method.

public ViewResult Process(string next) 
{
}

The above code is working fine in Chrome, but not in IE8/9. Can anyone help me out with this issue?

edit: I am wondering if this could be a common issue in MVC 3...I would love to know how one could possibly get around by using an image as I need to use the image.

Any help will be deeply apprecited...

Was it helpful?

Solution

It also won't work in Firefox. This is because image inputs do not submit the name as standard behavior. They only submit the x and y coordinates of the pixel clicked on the image.

You would do better to use a <button> element that contains an <img> tag.

I assume you have several buttons on your form and you want to know which button was clicked. There are several good solutions for this. For example:

http://weblogs.asp.net/dfindley/archive/2009/05/31/asp-net-mvc-multiple-buttons-in-the-same-form.aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top