我想要这个网址
/Admin/Product?page=1&keyword=somethingToSearch
但是当我在用户界面中提交表单时,“&keyword”不会出现。我不明白为什么。生成的网址只有这个:
/Admin/Product?page=1
Product.Controller :
public IActionResult Index(int page = 1, string keyword = "")
这是 UI 中的表单:
更多信息:此表单的作用是通过用户提交的关键字过滤数据,
input name="keyword"
。
<form asp-action="Index" class="d-flex">
<input type="hidden" name="page" [email protected]["page"] />
<input name="keyword" class="form-control me-2 w-50" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
这是整个index.html 标记
@using System.Reflection
@using Bulky.Models.Attributes;
@using System.ComponentModel.DataAnnotations;
@using System.ComponentModel
@{
var props = typeof(ProductVM2).GetProperties();
}
@model PaginatedList<ProductVM2>
<div class="card shadow border-0 mt-4">
<div class="card-header bg-secondary bg-gradient ml-0 py-3">
<div class="row">
<div class="col-12 text-center">
<h2 class="text-white py-2">Product List</h2>
</div>
</div>
</div>
<div class="card-body p-4">
<div class="row pt-4 pb-3">
<div class="col-6">
<a asp-controller="Product" asp-action="Upsert" class="btn btn-primary">
<i class="bi bi-plus-circle"></i>
Create New Product
</a>
</div>
</div>
<div class="row pt-4 pb-3">
@{
var pageQuery = Context.Request.Query["page"];
}
<input
name="keyword"
onchange="SubmitFiltering(@pageQuery, this.value)"
class="form-control me-2 w-50"
type="search"
placeholder="Search"
aria-label="Search"
>
<button class="btn btn-outline-success w-50" type="submit">Search</button>
</div>
<table class="table">
<thead>
<tr>
@foreach(var prop in props)
{
if(prop.GetCustomAttribute<HideProperty>() == null)
{
<th>
@(prop.GetCustomAttribute<DisplayNameAttribute>(true) != null ? prop.GetCustomAttribute<DisplayNameAttribute>(true).DisplayName : prop.Name)
</th>
}
}
<th scope="col"></th>
</tr>
</thead>
<tbody>
@if(Model.Count != 0 && Model != null)
{
@foreach (ProductVM2 item in Model.ToList())
{
<tr>
<td>@item.Title</td>
<td>@item.ISBN</td>
<td>@item.ListPrice</td>
<td>@item.Author</td>
<td>@item.Category.Name</td>
<td>
<a class="btn btn-primary" href="/admin/product/[email protected]">
<i class="bi bi-pencil-square"></i> Edit
</a>
<a class="btn btn-danger" href="/admin/product/[email protected]">
<i class="bi bi-trash-fill"></i> Remove
</a>
</td>
</tr>
}
}
</tbody>
</table>
<nav aria-label="...">
<ul class="pagination">
<li class="page-item @(!Model.HasPreviousPage ? "disabled" : "")">
<a asp-route-page=@(Model.PageIndex - 1) class="page-link" tabindex="-1" aria-disabled="true">
Previous
</a>
</li>
@if (Model.HasPreviousPage)
{
<li class="page-item">
<a class="page-link"
asp-route-page=@(Model.PageIndex - 1)>
@(Model.PageIndex - 1)
</a>
</li>
}
<li class="page-item active" aria-current="page">
<a class="page-link" href="#">@Model.PageIndex</a>
</li>
@if (Model.HasNextPage)
{
<li class="page-item">
<a
class="page-link"
asp-route-page=@(Model.PageIndex + 1)>
@(Model.PageIndex + 1)
</a>
</li>
}
<li class="page-item @(!Model.HasNextPage ? "disabled" : "")">
<a asp-route-page=@(Model.PageIndex + 1) class="page-link" >
Next
</a>
</li>
</ul>
</nav>
</div>
</div>