我正在尝试使用 actionLink 实现搜索功能。
actionLink 将为控制器提供参数,例如
@Html.ActionLink("Intel Core i5", "Search", "Store", new { @searchString = "i5" }, null)
我传递了这个值,它在控制器中工作。但是,当我尝试比较十进制数据类型而不是字符串数据类型时。目前,处理器是 varchar,而 displaySize 是十进制。
我不知道如何用 searchString 处理 displaySize。
我的控制器是这个。
//Controller here
public ActionResult Search(string searchString)
{
var product = from a in _db.Product.Include(a => a.Category)
select a;
if (!String.IsNullOrEmpty(searchString))
{
//processor is working because searchString is string, however,
//displaySize is not working because of decimal value, and
// I don't know how to write Where condition in here.
product = product.Where(a => a.processor.ToUpper().Contains(searchString.ToUpper())
||
//a.displaySize.ToString().Contains(searchString.ToUpper()));
//I repalce to below code, but it has error
//'Entity does not recognize the method ''System.String ToString()' method.
Convert.ToDecimal(a.displaySize).ToString().Contains(searchString)
}
return View(product.ToList());
}