[英]Call ActionResult method from button press
I'm trying to call an ActionResult method from a web page form but I can't seem get the two items to connect. 我正在尝试从网页表单中调用ActionResult方法,但似乎无法将两个项目连接起来。
The desired result is for the page to refresh and filter the model to display the required results. 期望的结果是页面刷新和过滤模型以显示所需的结果。
Method in serversController.cs serversController.cs中的方法
The internal code works as intended when placed in ActionResult Index
内部代码放在
ActionResult Index
时可以正常工作
[HttpPost]
public ActionResult activeServers()
{
// load the servers into local variable
var servers = from s in db.Servers
select s;
// filter out the archived servers
servers = servers.Where(s => s.archive.Equals(0));
return View(servers.ToList());
}
Button making the call 拨打电话的按钮
@using (Html.BeginForm())
{
<button name="activeServers" type="submit" value="activeServers" class="btn btn-default">Active</button>
}
Thanks is advance 谢谢提前
Try to specify the action method, controller name ( without the controller
suffix ) and the http method (it defaults to GET) in the BeginForm
: 尝试在
BeginForm
指定操作方法,控制器名称( 不带controller
后缀 )和http方法(默认为GET):
@using (Html.BeginForm("activeServers", "Servers", FormMethod.POST))
{
<button name="activeServers" type="submit" value="activeServers" class="btn btn-default">Active</button>
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.