如何在 ASP.NET MVC 中定义搜索过程的路径?
How can I define a route for search process in ASP.NET MVC?
我在 ASP.NET MVC 的控制器部分中定义关于 search 进程的路由时遇到问题.
我想要做的是在单击表单中的搜索按钮后获取下面定义的 URL。
Blog/Search?searchKeyword=banana
我创建了一个示例表单,但不知道如何在其操作中定义 url。我该怎么做?
这是与下面显示的表单代码片段相关的代码。
<form action="Blog/Search/" method="get">
<input type="text" name="searchKeyword">
<button type="submit"><i class="bi bi-search"></i></button>
</form>
下面是控制器部分定义的搜索函数。
[HttpGet]
[Route("Blog/Search/{searchKeyword}")]
public ActionResult BlogSearch(string search_string, int Sayfa = 1)
{
var searchList = db.Blog.Include("Category").Where(
x => x.Content.Contains(search_string)).OrderByDescending(x => x.BlogId).ToPagedList(Page, 5);
return View(searchList);
}
下面是我的回答。
js文件
<script type="text/javascript">
$(document).ready(function () {
$("#searchButton").click(function () {
var searchKeyword = $("#searchKeyword").val();
$.ajax({
url: '/Home/BlogSearch/',
data: {searchKeyword: searchKeyword},
type: 'POST'
});
});
})
</script>
博客搜索过程
public ActionResult BlogSearch(string search_string, int Sayfa = 1)
{
var searchList = db.Blog.Include("Kategori").Where(
x => x.Icerik.Contains(search_string)).OrderByDescending(x => x.BlogId).ToPagedList(Sayfa, 5);
return View(searchList);
}
我在 ASP.NET MVC 的控制器部分中定义关于 search 进程的路由时遇到问题.
我想要做的是在单击表单中的搜索按钮后获取下面定义的 URL。
Blog/Search?searchKeyword=banana
我创建了一个示例表单,但不知道如何在其操作中定义 url。我该怎么做?
这是与下面显示的表单代码片段相关的代码。
<form action="Blog/Search/" method="get">
<input type="text" name="searchKeyword">
<button type="submit"><i class="bi bi-search"></i></button>
</form>
下面是控制器部分定义的搜索函数。
[HttpGet]
[Route("Blog/Search/{searchKeyword}")]
public ActionResult BlogSearch(string search_string, int Sayfa = 1)
{
var searchList = db.Blog.Include("Category").Where(
x => x.Content.Contains(search_string)).OrderByDescending(x => x.BlogId).ToPagedList(Page, 5);
return View(searchList);
}
下面是我的回答。
js文件
<script type="text/javascript">
$(document).ready(function () {
$("#searchButton").click(function () {
var searchKeyword = $("#searchKeyword").val();
$.ajax({
url: '/Home/BlogSearch/',
data: {searchKeyword: searchKeyword},
type: 'POST'
});
});
})
</script>
博客搜索过程
public ActionResult BlogSearch(string search_string, int Sayfa = 1)
{
var searchList = db.Blog.Include("Kategori").Where(
x => x.Icerik.Contains(search_string)).OrderByDescending(x => x.BlogId).ToPagedList(Sayfa, 5);
return View(searchList);
}