我的项目带有剃须刀页面,我使用搜索输入和网站菜单中的按钮
菜单是索引页面中的componentView
@model IEnumerable<Lib.Model.DepartmentMenu>
<ul id="news-menu-item" class="row bg-Department" style="margin-left:0px !important; margin- right:0px !important; padding-right:0px; font-size:0.85rem">
<li style="width:2.5rem">
<a asp-page="/Index"><i class="fas fa-home"></i></a>
</li>
@foreach (var item in Model)
{
<li><a asp-page="/SubFolder/Index" asp-route-SFId="@item.Id">@item.Name</a></li>
}
<li >
<div class="d-flex justify-content-center h-90">
<form method="post" enctype="multipart/form-data" asp-page-handler= "Search"
class="searchbar">
<input class="search_input" type="text" name="search_main" placeholder="search...">
<button class="search_icon"><i class="fas fa-search"></i></button>
</form>
</div>
</li>
</ul>
并为菜单中的句柄搜索按钮添加 asp-page-handler =“ Search” ,在索引页中,我将post方法与处理程序一起放置的是:
public async Task<IActionResult> OnPostSearchAsync(IFormCollection fc)
{
return RedirectToPage("/searchResult/", new { searchParam = searchText });
}
如您所点击的搜索按钮所看到的那样,将在搜索输入中输入的文字发送到搜索结果页面,网址将是
www.thissite.com/earchresulth?searchparam=“ test”
访问者在索引页面(“网站根目录”)中的搜索按钮可以正常工作 我的问题是何时:
用户导航到另一个页面,如:www.thissite.com/ 关于我们,然后再次搜索=>当将搜索按钮的URL更改为
时/ aboutUs?searchparam =“ test”
和不要重定向到
www.thissite.com/earchresulth?searchparam=“ test”
我该如何解决?
index.cshtml中用于处理seachComponent的处理程序是:
public async Task<IActionResult> OnPostSearchAsync(IFormCollection fc)
{
return RedirectToPage("/searchResult/", new { searchParam = searchText });
}
searchresult.cshtml是
public void OnGet(string searchParam)
{
//.ToList();
}