10

我按照这篇文章的说明进行操作: Asp.net mvc3 razor with multiple submit buttons ,这是我的模型:

public class AdminModel
{
  public string Command { get; set; }
}

我的控制器

[HttpPost]
public ActionResult Admin(List<AdminModel> model)
{
   string s = model.Command;
}

我的观点

@using (Html.BeginForm("Admin", "Account"))
{
  <input type="submit" name="Command" value="Deactivate"/>
  <input type="submit" name="Command" value="Delete"/>
}

当我回帖时,字符串“s”始终为空。

我还在这个论坛帖子中尝试了第二个答案(获得 146 票的那个):How do you handle multiple submit buttons in ASP.NET MVC Framework?那也是空的。我究竟做错了什么?

4

2 回答 2

24

您需要通过按钮名称从他们的服务器端获取值,

public ActionResult Admin(List<AdminModel> model,string Command)
{
   string s = Command;
}
于 2012-04-20T16:48:35.010 回答
0

从我在发布的代码中可以看到,您不会将模型列表发送到控制器,而只是发送一个模型实例。尝试将控制器修改为:

[HttpPost]
public ActionResult Admin(AdminModel model)
{
   string s = model.Command;
}
于 2012-04-20T16:46:45.023 回答