title: How can I create a search functionality with partial view in asp.net mvc 4
body: <p>I am using ASP.NET MVC 4 with entity framework model first.</p>
  
  <p>In my "Masterpage.cshtml" I want to have a partial view which contains a textbox and a button. </p>
  
  <p>The search is looking for the items title, if the text contains a items title it should display those items.</p>
  
  <p>When a text is submitted the <code>@renderbody()</code> should show a view with the items.</p>
  
  <p>My question is how can I do this in a good way? whats a good and easy approach?</p>
  
  <p>So far I have done this:</p>
  
  <p>Created a method in my repository that does the search function:</p>
  
  <pre><code>public List&lt;News&gt; Search(string query)
          {
  
              var queryz =  db.News.Where(x =&gt; x.Title.Contains(query));
              return queryz.ToList();
          }
  </code></pre>
  
  <p>Now when it comes to my Searchcontroller im kinda lost how to do this. Beacuse one actionresult need to be the partialview that has a string query parameter and other one that contains a view that will display the items?</p>
  
  <p>What I have done right now is having the whole process in same actionresult:</p>
  
  <pre><code> Repository rep = new Repository();
          [HttpPost]
          public ActionResult Search(string query)
          {
              var searchlist = rep.Search(query);
  
              var model = new ItemViewModel()
              {
                  NewsList = new List&lt;NewsViewModel&gt;()
              };
  
              foreach (var NewsItems in searchlist)
              {
                  FillProductToModel(model, NewsItems);
              }
  
              return View(model);
          }
  
          private void FillProductToModel(ItemViewModel model, News news)
          {
              var productViewModel = new NewsViewModel
              {
  
                  Description = news.Description,
                  NewsId = news.Id,
                  Title = news.Title,
                  link = news.Link,
                  Imageurl = news.Image,
                  PubDate = news.Date,
              };
              model.NewsList.Add(productViewModel);
          }
  </code></pre>
  
  <p>any kind of help is appreciated alot!</p>