即時通訊非常新的MVC3,我負責添加一個搜索框到我的MVC3控制器,並使控制器顯示結果基於從數據庫搜索。MVC LinQ搜索錯誤
我的代碼粘貼在下面,拋出一個錯誤,錯誤信息也被粘貼。
public ViewResult Index(string searchString)
{
var newsItem = from n in db.NewsItems
select n;
if (!String.IsNullOrEmpty(searchString))
{
newsItem = newsItem.Where(n => n.Posted.ToUpper().Contains(searchString.ToUpper())
|| n.Posted.ToUpper().Contains(searchString.ToUpper()));
}
return View(db.NewsItems.ToList());
}
錯誤:
'System.DateTime' does not contain a definition for 'ToUpper' and no extension method 'ToUpper' accepting a first argument of type 'System.DateTime' could be found (are you missing a using directive or an assembly reference?)
C:\Documents and Settings\Administrator\My Documents\Visual Studio 2010\Projects\Web_Assignment\Web_Assignment\Controllers\NewsController.cs 27 40 Web_Assignment
這功課嗎?你的錯誤是相當具有描述性的。 – 2012-02-01 19:11:10