2010-08-16 48 views
1

我使用MVC2/asp.net並嘗試開發類似嚮導的東西。這個嚮導將有幾個網站。 用戶將能夠在網站A上輸入一些信息,然後導航到網站B(通過按下觸發Http.Post事件的按鈕)。 到目前爲止沒有問題。如何識別是否按下「返回」按鈕或「前進」按鈕?

同樣在網站B上,用戶可以輸入一些信息。但是他有兩個按鈕:「後退」和「前進」。

如何在這裏識別哪個按鈕被按下?

[AcceptVerbs(HttpVerbs.Post)] 
public ActionResult Step2(Model model, FormCollection Form) 
{ 
... 
} 

「後退」/ 「前進」 按鈕看起來像這樣:

INPUT TYPE = 「圖像」 名稱= 「返回按鈕」 ID = 「返回按鈕」 SRC =「HTTP:// .. .whatever .../Resources/Images/Button/BackButton.gif「alt =」Back「/>

input type =」image「name =」ForwardButton「id =」ForwardButton「src =」http:// ...無論.../Resources/Images/Button/Forward.gif「alt =」Forward「/>

回答

1

通過查看FormCollection Form只有按鈕如果我沒有記錯,回傳應該在場。

,並在MVC2您可以鍵入[HttpPost]而不是[AcceptVerbs(HttpVerbs.Post)]

+0

非常感謝您爲您的快速和良好的重播! 你說得對。 FormCollection僅包含按下的按鈕。 – user415876 2010-08-16 08:59:44

0

如果你不想看從集合,你可以裝點行動PARAMATERS

[AcceptVerbs(HttpVerbs.Post)] 
public ActionResult Step2(Model model, string Backbutton, string ForwardButton) 
{ 
    ///depending on that is clicked the string will be null or not 
    if(Backbutton !== null) 
    { //back button was pressed 
    } 

    if(Forwardbutton !== null) 
    { //forward button was pressed 
    } 
}