如何判断是否“返回”按钮或“前进”按钮被按下?

发布于 2024-09-15 04:00:52 字数 625 浏览 8 评论 0原文

我使用 MVC2/asp.net 并尝试开发类似向导的东西。该向导将有几个网站。 用户将能够在网站 A 上输入一些信息,然后导航到 网站 B(通过按下触发 Http.Post 事件的按钮)。 到目前为止没有问题。

用户还可以在网站 B 上输入一些信息。但他有两个按钮:“后退”和“前进”。

如何识别按下了哪个按钮?

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

“后退”/“前进”按钮如下所示:

input type="image" name="BackButton" id="BackButton" src="http: //...无论如何.../Resources/Images/Button/BackButton.gif" alt="返回" />

输入类型=“图像”名称=“ForwardButton”id=“ForwardButton”src=“http://...whatever.../Resources/Images/Button/Forward.gif”alt=“Forward”/>

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 "Back" / "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" />

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猫弦 2024-09-22 04:00:52

如果我没记错的话,通过查看FormCollection Form,只有执行回发的按钮应该出现。

在 mvc2 中,您可以输入 [HttpPost] 而不是 [AcceptVerbs(HttpVerbs.Post)]

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

别把无礼当个性 2024-09-22 04:00:52

如果您不想查看 From 集合,您可以装饰 Action 参数

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

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
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文