使用两个单提交表单内按钮 [英] using two submit buttons inside single form
问题描述
我有两个表单提交在我的asp.net MVC(C#)应用程序按钮。当我点击任何谷歌浏览器
,默认提交按钮的值是第一个提交按钮的值。
I have a form with two submit buttons in my asp.net mvc (C#) application. When i click any submit button in Google Chrome
, by default the value of submit button is the first submit button's value.
下面是HTML:
<input type="submit" value="Send" name="SendEmail" />
<input type="submit" value="Save As Draft" name="SendEmail" />
<input type="button" value="Cancel" />
当我点击控制器的动作另存为草稿
按钮,它就会被发送作为 SendEmail 价值code>。
When i click the Save As Draft
button, in the action of the controller, it gets "Send" as the value for SendEmail
.
下面是动作:
public ActionResult SendEmail(string SendEmail, FormCollection form)
{
if(SendEmail == "Send")
{
//Send Email
}
else
{
//Save as draft
}
return RedirectToAction("SendEmailSuccess");
}
当我从的FormCollection获得的价值,它显示发送。即表格[SendEmail]
给发送
When i get the value from FormCollection, it shows "Send". i.e. form["SendEmail"]
gives Send
可能是什么问题或解决,我需要做的就是被点击提交按钮的实际价值?
What may be the problem or work around i need to do to get the actual value of the clicked submit button?
推荐答案
显示此页。
<一个href=\"http://weblogs.asp.net/dfindley/archive/2009/05/31/asp-net-mvc-multiple-buttons-in-the-same-form.aspx\">ASP.NET MVC - 在同一形式的多个按钮 - 大卫芬德利的博客
创建ActionMethodSelectorAttribute继承类。
Create ActionMethodSelectorAttribute inherit class.
这篇关于使用两个单提交表单内按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!