Wyszukiwanie produktu po nazwie

0

Witam.

Chciałbym w swoim projekcie zrobić sobie proste wyszukiwanie. Niby wszystko robię dobrze ale jednak coś nie działa :P

W widoku mam szukaczkę:

 
 @using(Html.BeginForm("Find","Home", FormMethod.Post))
        {
            <input type="text"  id="txt" name="txt" class="wyszukiwarka pull-right" placeholder="Wpisz nazwę produktu aby wyszukać" />
        }

Następnie w kontrolerze mam akcje odpowiadającą za wyszukiwanie:

 
[HttpPost]
        public ActionResult Find(string txt)
        {
            if (txt != String.Empty)
            {
                using (var db = new ApplicationDbContext())
                {
                    var foundProduct = db.Products.Where(n => n.ProductName == txt).ToList();
                    return View(foundProduct);
                }    
            }
            return View();
        }

No i w widoku kolejnym chce zwrócić liste rekordów spełniających zadane kryterium

 
@model List<Myproject.Models.Product>

@{
    ViewBag.Title = "Rezultat";
}

<br /><br /><br />
<h2>Rekordy spełniające zadane kryterium</h2>
<br />
<div>
    <table class="table table-striped table-bordered table-condensed">
        <thead>
            <tr>
                <th>ID</th>
                <th>Nazwa produktu</th>
                <th>Zdjęcie produktu</th>
                <th>Opis produktu</th>
                <th>Cena za sztuke</th>
                <th>Ilość sztuk na stanie</th>
                <th>Punkty premium</th>
                <th>Opcje</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in Model)
            {
                <tr>
                    <td>@item.Id</td>
                    <td>@item.ProductName</td>
                    <td style="width:150px; height: 150px;"><img src="@Url.Content(item.ProductImageUrl)" alt="" /></td>
                    <td>@item.ProductDescription</td>
                    <td style="width: 150px; height: 150px;">@item.PricePerUnit</td>
                    <td>@item.ProductQuantity</td>
                    <td>@item.PremiumPoints</td>
                    <th style="width: 150px; height: 150px;">
                        @Html.ActionLink("Sprawdź produkt", "Details", "Products") <br />
                        @if (Request.IsAuthenticated && User.Identity.IsAuthenticated && User.IsInRole("Normalny"))
                        {
                            <p>@Html.Label("Wybierz ilość sztuk")</p>
                            @Html.TextBox("PodajIlosc", "", new { @Style = "width: 92%" }) <br />
                            @Html.ActionLink("Dodaj do koszyka", "BuyProducts")
                        }
                        @if (Request.IsAuthenticated && User.Identity.IsAuthenticated && User.IsInRole("Administrator"))
                        {
                            @Html.ActionLink("Edytuj produkty", "EditProduct")<br />
                            @Html.ActionLink("Usuń produkty", "RemoveProduct")<br />
                        }



                    </th>
                </tr>
            }
        </tbody>
    </table>
    <br /><br /><br />
    <br /><br /><br />

</div>

Debugowałem to i okazuje się, że ten parametr string productName jest nullem. Ale to sobie już naprawiłem natomiast chyba jest coś nie tak z moim query bo kolekcja jest nullem

Druga sprawa to czy ktoś wie jak zastosować do tego Lucene .NET aby przyśpieszyć wyszukiwanie?

0

Ok już na to wpadłem. Poprawna akcja w kontrolerze ma być taka:

 
[HttpPost]
        public ActionResult Find(string txt)
        {
            if (txt != String.Empty)
            {
                using (var db = new ApplicationDbContext())
                {
                    var foundProduct = db.Products.Where(d=>d.ProductName.ToUpper().Contains(txt.ToUpper()));
                    return View(foundProduct.ToList());
                }    
            }
            return View();
        }

Natomiast wie ktoś jak zastosować to Lucine .NET aby indeksować rekordy?

1 użytkowników online, w tym zalogowanych: 0, gości: 1