リンクからの検索機能を作りたい。
現在、ホームページに検索ボックスがあります。検索ボックスを動作させています。
ただし、いくつかのパラメーターをコントローラーの Search メソッドに渡す方法がわかりません。
このようにコーディングすると、コントローラーで searchString が「null」になります。
actionLink を介して serachString パラメータを取得するにはどうすればよいですか?
私たちを手伝ってくれますか?たぶん簡単に見えます。私を助けてください、または私にアドバイスしてください。ありがとう。
//mac.cshtml
<h3>CPU Processor</h3>
<ul>
<li>@Html.ActionLink("Intel Core i5", "Search", "Store", new { @searchString = "i5"})</li>
<li>@Html.ActionLink("Intel Core i7", "Search", "Store", new { @searchString = "i7" })</li>
</ul>
//Search method in StoreController
public ActionResult Search(string searchString)
{
var product = from a in _db.Product.Include(a => a.Category)
select a;
if (!String.IsNullOrEmpty(searchString))
{
product = product.Where(a => a.model.ToUpper().Contains(searchString.ToUpper())
|| a.Category.name.ToUpper().Contains(searchString.ToUpper()));
}
return View(product.ToList());
}