Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

[ASP.NET 5 / MVC 6] How to make a search box and receive input value in Search Action?

$
0
0

Hi guys, I am building a page to show some list content.

And I want to make a search box for users to input keywords to filter the lists.

So I made a search box like this

<form asp-controller="ChangeTypes" asp-action="Search" method="get"><input name="Search" id="Search"/><input type="submit" value="Submit" /><a asp-action="Search">Submit</a></form>

and then, I wrote Search Action of ChangeTypes Controller like this

        [HttpGet]
        public IActionResult Search(string strFilter)
        {
            strFilter.Trim();
            var data = from c in _context.ChangeType
                       where c.HName.Contains(strFilter) || c.HRemark.Contains(strFilter)
                       select c;
            return View("Index", data);
        }

also, I have an Index Action

 public IActionResult Index(int page =0)
        {
            const int pageSize = 10;
            var count = _context.ChangeType.Count();
            var data = _context.ChangeType.Skip(page * pageSize).Take(pageSize);
            var maxPage = (count / pageSize) - (count % pageSize == 0 ? 1 : 0);
            this.ViewBag.Page = page;
            this.ViewBag.MaxPage = maxPage;

            return View(data);
        }

Every time I click on the submit button, the system redirect to INDEX ACTION, not the expected SEARCH ACTION.

Could you guys please show me some ASP.NET MVC 6 method to achieve my goal...

:)

I mean, not the previous asp.net mvc 4/5 methods, if the method of 6 and 4/5 is different;

thank you.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>