我们可以在一个视图中有多个提交按钮用于不同的操作吗? [英] Can we have mutiple Submits Button in a View for different operations?

查看:45
本文介绍了我们可以在一个视图中有多个提交按钮用于不同的操作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 4 个提交按钮来执行不同的操作.对于一次提交,我是这样写的

I have a 4 submit buttons to do different action operation's. For One Submit I have written like this

@using (Html.BeginForm("Edit", "Seller", FormMethod.Post)){ 

}

对于多个提交按钮,我们该怎么办?我们是否需要为每个提交按钮编写相同的内容?

How can we do for multiple Submit buttons ? Do we need to write the same for every Submit button?

推荐答案

这里是如何为两个提交按钮执行此操作,类似地,您可以为 'n' 个提交按钮执行此操作.

Here is how you do it for two submit buttons, similary you can do this for 'n' submit buttons.

下面是一个带有两个提交按钮的表单.请注意,这两个提交按钮具有相同的名称,即submitButton"

Below is a form with two submit buttons. Note that both these submit buttons have the same name i.e "submitButton"

@Html.BeginForm("MyAction", "MyController"); %>
<input type="submit" name="submitButton" value="Button1" />
<input type="submit" name="submitButton" value="Button2" />
}

现在到 Controller 了,Action 接受一个名为 stringStringButton 的输入参数,其余的非常不言自明.

Now over to the Controller, the Action takes in an input parameter called string stringButton and the rest is pretty self-explanatory.

public ActionResult MyAction(string submitButton) {
        switch(submitButton) {
            case "Button1":
               // do something here
            case "Button2":
               // do some other thing here
            default:
                // add some other behaviour here
        }
...
}

这篇关于我们可以在一个视图中有多个提交按钮用于不同的操作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆