如何放置两个表单提交按钮 [英] How to place two submit buttons in form

查看:175
本文介绍了如何放置两个表单提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个在一个表单提交按钮。我想打电话给在两个按钮不同的操作。有什么办法做到这一点不使用JavaScript。

I have two submit buttons in one form. I want to call different actions in both buttons. Is there any way to accomplish this without using JavaScript.

推荐答案

调用不同的动作也不是没有可能的JavaScript。你可以调用相同的控制器动作,因此这个动作内确定哪个按钮是使用name属性pressed:

Calling different actions is not possible without javascript. You could call the same controller action and inside this action determine which button was pressed using the name property:

<% using (Html.BeginForm()) { %>
    <input type="submit" name="save" value="Save" />
    <input type="submit" name="update" value="Update" />
<% } %>

和在你的控制器动作:

[HttpPost]
public ActionResult Index(string save)
{
    if (!string.IsNullOrEmpty(save))
    {
        // the save button was pressed
    }
    else
    {
        // the update button was pressed
    }
    return View();
}

这篇关于如何放置两个表单提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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