0

我正在尝试使用 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());
    }
4

1 回答 1

1

绝对a.displaySize.ToString().Contains(searchString.ToUpper()));不会达到目的。尝试将十进制值的整数部分与搜索字符串进行比较,以获得更准确的结果。像这样Convert.ToInt32(a.displaySize).ToString().Contains(searchString)

于 2012-04-13T12:29:59.160 回答