View 通过单击属性将值从视图传递到控制器

View 通过单击属性将值从视图传递到控制器,view,asp.net-core,controller,View,Asp.net Core,Controller,我正试图将这些值传递回我的控制器进行一些基本的分页,我不知道为什么它不能得到它们 我是否错误地使用asp路线来传递它们 视图: 控制器: [HttpPost, ActionName("Index")] [ValidateAntiForgeryToken] public async Task<IActionResult> IndexPost(string certification, string category, string resource,

我正试图将这些值传递回我的控制器进行一些基本的分页,我不知道为什么它不能得到它们

我是否错误地使用asp路线来传递它们

视图:

控制器:

 [HttpPost, ActionName("Index")]
        [ValidateAntiForgeryToken]
        public async Task<IActionResult> IndexPost(string certification, string category, string resource, int prev, int next)
上面的代码呈现了一个标记,如果您单击它,它会向action方法发出HttpGet请求

如果您想制作HttpPost,则需要使用表单标记和按钮或输入标记,并键入submit

<ul class="pager">
    <li class="previous">
       <form asp-controller="Home" asp-action="Index" 
             asp-route-prev="@Model.First().ID" method="post" role="form">
           <button type="submit">Previous</button>
       </form>
    </li>
</ul>
另一种方法是在单击时使用JavaScript或jQuery发布表单,但这有点超出了原始问题的范围

<a asp-action="Index" asp-route-prev="@Model.First().ID">Previous</a> 
<ul class="pager">
    <li class="previous">
       <form asp-controller="Home" asp-action="Index" 
             asp-route-prev="@Model.First().ID" method="post" role="form">
           <button type="submit">Previous</button>
       </form>
    </li>
</ul>