我有一个下拉菜单,其中包含我在剃刀列表中使用的每页行的值。剃刀列表已配置有分页,排序和过滤功能。
选择输入在这里:
<div class="col-3 pr-0">
<select asp-for="@Model.RowsPerPage" class="form-control" onchange="onChangeRowsPerPageSelect()" id="rowsPerPageSelect">
<option value="">Select</option>
<option value="10">10</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="500">500</option>
<option value="1000">1000</option>
</select>
</div>
以下是列表视图的列标题之一,单击该列标题将在页面模型中调用OnGet及其相关的sort by和filter url。
<th>
<a asp-page="./Index" asp-route-sortOrder="@Model.NameSort"
asp-route-rowsPerPage="10"
asp-route-currentFilter="@Model.CurrentFilter">
@Html.DisplayNameFor(model => model.TcpServer[0].Name)
</a>
</th>
在上面的表头代码中,您可以看到我已经用10值对asp-route-rowsPerPage进行了硬编码,这行得通,但是我所坚持的是如何从选择下拉框中获取所选值?
将select放入表单中,然后提交onchange事件:
<form method="get">
<select asp-for="@Model.RowsPerPage" onchange="this.form.submit()">
<!-- options... -->
</select>
<!-- put other filters inside the form as well -->
</form>
RowsPerPage
从模型获取值:
<a asp-route-rowsPerPage="@Model.RowsPerPage"
.
.
.>
@Html.DisplayNameFor(model => model.TcpServer[0].Name)
</a>
在后端,您应该使用OnGet()
方法并为启用绑定RowsPerPage
:
public class IndexModel : PageModel
{
[BindProperty(SupportsGet = true)]
public int RowsPerPage { get; set; } = 10;
// Do the same for other filters...
public void OnGet()
{
// ...
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句