Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MVC LinQ搜索错误_Linq_Asp.net Mvc 3 - Fatal编程技术网

MVC LinQ搜索错误

MVC LinQ搜索错误,linq,asp.net-mvc-3,Linq,Asp.net Mvc 3,我是MVC3的新手,我的任务是在我的MVC3控制器中添加一个搜索框,并使控制器根据数据库中的搜索显示结果 我的代码粘贴在下面,抛出一个错误,错误消息也被粘贴 public ViewResult Index(string searchString) { var newsItem = from n in db.NewsItems select n; if (!String.IsNullOrEmpty(searchS

我是MVC3的新手,我的任务是在我的MVC3控制器中添加一个搜索框,并使控制器根据数据库中的搜索显示结果

我的代码粘贴在下面,抛出一个错误,错误消息也被粘贴

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”不包含“ToUpper”的定义,并且没有 扩展方法“ToUpper”接受类型为的第一个参数 找不到“System.DateTime”(是否缺少using指令或 组件参考?
C:\Documents and Settings\Administrator\My 文档\ Visual Studio 2010\Projects\Web\u Assignment\Web\u Assignment\Controllers\NewsController.cs 27 40 Web\u Assignment


我认为发布的属性具有DateTyme类型。然后,如果您真的想在DateTime列中搜索,则需要将其转换为字符串类型:
newItem.Where(n=>n.Posted.ToString().ToUpper().Contains(searchString.ToUpper())
但也许你真的想在文本属性中搜索

newsItem.Where(n => n.Text.ToUpper().Contains(searchString.ToUpper())

这是家庭作业吗?你的错误描述得很清楚。