我在asp.net mvc(C#)應用程序中有兩個提交按鈕的窗體。當我單擊Google Chrome
中的任何提交按鈕時,默認情況下,提交按鈕的值是第一個提交按鈕的值。在單個窗體中使用兩個提交按鈕
下面是HTML:
<input type="submit" value="Send" name="SendEmail" />
<input type="submit" value="Save As Draft" name="SendEmail" />
<input type="button" value="Cancel" />
當我點擊Save As Draft
按鈕,在控制器的作用下,它被「發送」爲SendEmail
值。
這裏是動作:
public ActionResult SendEmail(string SendEmail, FormCollection form)
{
if(SendEmail == "Send")
{
//Send Email
}
else
{
//Save as draft
}
return RedirectToAction("SendEmailSuccess");
}
當我得到的FormCollection的價值,它顯示了 「發送」。即form["SendEmail"]
給出Send
什麼可能是問題或解決辦法我需要做的,以獲得點擊提交按鈕的實際價值?
您的代碼看起來不錯,該技術應該工作。可能會嘗試檢查HTTP POST以查看究竟是什麼被髮送回服務器。 – DavGarcia 2010-03-11 06:51:50
它只發生在谷歌瀏覽器中,但在IE和Firefox中,它運行良好。 – Prasad 2010-03-11 06:56:17
Chrome是什麼? – Ted 2013-12-04 00:51:30