Asp.net MVC3剃须刀具有多个提交按钮 [英] Asp.net mvc3 razor with multiple submit buttons

查看:127
本文介绍了Asp.net MVC3剃须刀具有多个提交按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MVC3剃刀。我有2个提交我的视图按钮的设置,但我遇到的问题是,这两个提交按钮导致模型的验证。我想挂钩个人提交具体的输入控件按钮进行验证。

I'm using MVC3 Razor. I have 2 submit buttons setup on my view but the problem I'm having is that both submit buttons cause the validation of the model. I want to hook up individual submit buttons with specific input controls for validation.

推荐答案

我知道这是一个几个月大,但解决方案在这里似乎是不必要的复杂性,而且也没有公认的答案。如果你的名字你输入相同,但给他们不同的价值观,你就能通过包括与输入作为变量名的字符串帮助你在控制器的价值。这是我如何解决了这个问题:

I know this is a few months old but the solutions here seemed needlessly complex and there's no accepted answer yet. If you name your inputs the same but give them different values, you can get that value in your controller just by including a string with the name of the input as a variable. This is how I solved this problem:

查看:

 <input type="submit" id="EnterprisePush" name="btnSubmit" value="Push" />
 <input type="submit" id="EnterprisePull" name="btnSubmit" value="Pull" />

控制器:

[HttpPost]
public ActionResult EnterpriseAdmin(int id, string btnSubmit, FormCollection collection)
{
  switch (btnSubmit) {
    case "Push":
      /* Do Something here */
      break;
    case "Pull":
      /* Do Something else here */
      break;
  }

这篇关于Asp.net MVC3剃须刀具有多个提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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