How to implement search features in ASP.NET MVC applications

前端 未结 2 832
醉梦人生
醉梦人生 2020-12-13 20:47

I can imagine many ways of implemeting search features in an ASP.NET MVC application but since I can\'t find much documentation I was wondering if you have any common patter

相关标签:
2条回答
  • 2020-12-13 20:56

    I believe in one of his blog posts Jeff Atwood talks about how he used sitemaps in order to let google handle most of the searching capabilities on stack overflow. Why write your own searching algorithms when people are likely just going to use google anyway?

    0 讨论(0)
  • 2020-12-13 21:14

    It's not entirely clear what you are specifically asking, but, in general:

    1. Write a view helper or partial view which returns a search form. Call that within your other pages wherever you need to display a search box. Make the form action GET, not POST.
    2. For a site search, you'll probably want to have a search controller. For searching within one particular type of data, you can add an action to an existing controller or an argument to an existing action. For the most part, the only thing that we have to add is an argument to the general-purpose "List" action for a specific datatype. The search form calls "List" and sets an argument with the search query string.
    3. The actual searching is done within your Repository. That's the only part of the application which knows about things like SQL Server or Lucene. For trivial cases a controller could append a .Where to an IQueryable<T> returned by a Repository.
    0 讨论(0)
提交回复
热议问题