如何识别是否按下“返回”按钮或“前进”按钮?

问题描述:

我使用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“/>

通过查看FormCollection Form只有按钮如果我没有记错,回传应该在场。

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

+0

非常感谢您为您的快速和良好的重播! 你说得对。 FormCollection仅包含按下的按钮。 – user415876 2010-08-16 08:59:44

如果你不想看从集合,你可以装点行动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 
    } 
}