Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3302df3

Browse files
committed
Add Search
1 parent c3ff75e commit 3302df3

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

‎src/NetCoreBBS/Controllers/HomeController.cs‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ public IActionResult Index([FromServices]IUserServices user)
2121
{
2222
var pagesize = 20;
2323
var pageindex = 1;
24+
var topics = _context.Topics.AsQueryable();
2425
if (!string.IsNullOrEmpty(Request.Query["page"]))
2526
pageindex = Convert.ToInt32(Request.Query["page"]);
26-
var count= _context.Topics.Count();
27-
ViewBag.Topics = _context.Topics
27+
if (!string.IsNullOrEmpty(Request.Query["s"]))
28+
topics = topics.Where(r => r.Title.Contains(Request.Query["s"]));
29+
var count= topics.Count();
30+
ViewBag.Topics = topics
2831
.OrderByDescending(r => r.CreateOn)
2932
.OrderByDescending(r => r.Top)
3033
.Skip(pagesize*(pageindex-1))

‎src/NetCoreBBS/Views/Shared/_Layout.cshtml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
</div>
3333
<div id="navbar" class="navbar-collapse collapse">
3434
@await Html.PartialAsync("_LoginPartial")
35-
<form class="navbar-form navbar-right">
36-
<input type="text" class="form-control" placeholder="搜索...">
35+
<form class="navbar-form navbar-right"asp-controller="Home"asp-action="Index"method="get">
36+
<input type="text" class="form-control" name="s"placeholder="搜索...">
3737
</form>
3838
</div>
3939
</div>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /