开发者

How to identify whether "Back" button or "Forward" button was pressed?

I use MVC2/asp.net and try to develop something like a wizard. This wizard will have several websites. The user will be able to enter some information on website A and to navigate then to website B (by pressing a button which triggers the Http.Post event). No problem up to this point.

Also on website B can the user enter some information. But there he has two buttons: "Back" and "Forward".

How to identify here which button was pressed?

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

The "Ba开发者_运维知识库ck" / "Forward" buttons look like this:

input type="image" name="BackButton" id="BackButton" src="http://...whatever.../Resources/Images/Button/BackButton.gif" alt="Back" />

input type="image" name="ForwardButton" id="ForwardButton" src="http://...whatever.../Resources/Images/Button/Forward.gif" alt="Forward" />


By looking through FormCollection Form only the button that did the postback should be present if I remember correctly.

and in mvc2 you can type [HttpPost] instead of [AcceptVerbs(HttpVerbs.Post)]


If you dont want to look at From collection you could decorate the Action 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
  }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜