0

I am working on an ASP.NET MVC 2 portal. My requirement is something like below:

<form action = "mvc2proj/ControllerName/ActionName/1234" method="post">
  CheckBox 1 to select first item
  CheckBox 2 to select second item
  CheckBox 3 to select third item
  CheckBox 4 to select fourth item
  "Buy Now" image button
</form>

I am using HTML.BeginForm() to generate "form" element as:

<%Html.BeginForm("ActionName", "ContrllerName", new {id=1234}, FormMethod="Post");%>

When I use HTML submit button, I am able to get form values on "ActionName" action of the "ControllerName" controller. But since it should be an image button rathar than a regular HTML submit button.

So how will I be able to use an IMAGE BUTTON inside HTML.BeginForm()?

1 Answer 1

3

This should work. Your form:

<% using (Html.BeginForm("MyAction", "Home")){ %>

<%=Html.CheckBox("Item1") %>
<%=Html.CheckBox("Item2") %>
<%=Html.CheckBox("Item3") %>
<%=Html.CheckBox("Item4") %>

<button name="button"><img src="yourimage.png" /></button>

<% } %>

And the corresponding action:

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult MyAction(string Item1, string Item2, string Item3, string Item4)
{
    return View();
}
Sign up to request clarification or add additional context in comments.

3 Comments

Yes...You are right. I have already seen this solution. But intellisense does not show SubmitImage helper function. I am using MVC 2 and my development environment is VS2010.
My bad. Updated my answer to something that works. Sorry about that.
Why don't we use input type=image HTML submit button? It works for me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.