Asp.net mvc MVC4-一个表单2提交按钮
我遵循了这篇帖子上的说明: 这是我的模型:Asp.net mvc MVC4-一个表单2提交按钮,asp.net-mvc,forms,submit,Asp.net Mvc,Forms,Submit,我遵循了这篇帖子上的说明: 这是我的模型: public class AdminModel { public string Command { get; set; } } 我的控制器 [HttpPost] public ActionResult Admin(List<AdminModel> model) { string s = model.Command; } [HttpPost] public ActionResult Admin(列表,该值也为空。我做错了什么?从
public class AdminModel
{
public string Command { get; set; }
}
我的控制器
[HttpPost]
public ActionResult Admin(List<AdminModel> model)
{
string s = model.Command;
}
[HttpPost]
public ActionResult Admin(列表,该值也为空。我做错了什么?从发布的代码中可以看出,您没有向控制器发送模型列表,只发送一个模型实例。请尝试将控制器修改为:
[HttpPost]
public ActionResult Admin(AdminModel model)
{
string s = model.Command;
}
您需要通过按钮的名称从服务器端获取值
public ActionResult Admin(List<AdminModel> model,string Command)
{
string s = Command;
}
公共操作结果管理(列表模型,字符串命令)
{
字符串s=命令;
}
哇,我想我试过了,在我帖子的第二个论坛上。我不知道我当时做错了什么。现在可以了,谢谢。请注意,当使用
标记而不是
标记时,在一个表单字段中按Enter键,命令
参数将不会被设置,因此将为null
。您可以处理这个问题t通过使用Javascript捕获按键事件,或者简单地通过在控制器操作中设置默认值:public ActionResult Admin(List model,string Command=“Deactivate”)
我的视图正在接收AdminModel:)列表。这个怎么样?
public ActionResult Admin(List<AdminModel> model,string Command)
{
string s = Command;
}