2010-08-19 36 views
0

我正在開發ASP.NET MVC 2門戶。我的要求是像下面的東西:HTML.BeginForm中的ASP.NET MVC圖像按鈕問題

<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> 

我使用HTML.BeginForm(),生成「形式」的元素:

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

當我使用HTML提交按鈕,我能拿到形式「ControllerName」控制器的「ActionName」操作的值。但是因爲它應該是一個圖像按鈕而不是普通的HTML提交按鈕。

那麼我怎麼能夠在HTML.BeginForm()中使用圖像按鈕?

回答

3

這應該工作。您的形式:

<% 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> 

<% } %> 

而相應的動作:

[AcceptVerbs(HttpVerbs.Post)] 
public ActionResult MyAction(string Item1, string Item2, string Item3, string Item4) 
{ 
    return View(); 
} 
+0

是......你是對的。我已經看到這個解決方案。但智能感知不顯示SubmitImage幫助器功能。我使用的是MVC 2,我的開發環境是VS2010。 – user423719 2010-08-19 12:28:14

+0

我的不好。更新我的答案,一些有效的東西。對於那個很抱歉。 – Tchami 2010-08-23 08:37:12

+1

爲什麼我們不使用input type = image HTML提交按鈕?這個對我有用。 – user423719 2010-09-06 08:33:22