2012-04-12 72 views
0

我想通過鏈接進行搜索功能。帶搜索功能的MVC3 ActionLink

當前,我在主頁上有搜索框。它正在搜索框中工作。

但是,我不知道如何將一些參數傳遞給控制器​​中的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()); 
    } 

回答