在文本框中搜索多个值 - mvc [英] search multiple values in a textbox - mvc

查看:78
本文介绍了在文本框中搜索多个值 - mvc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,



我正在尝试查询,以便能够在一个文本框中搜索tagfieldname的多个值。我不清楚这项任务的正确方法是什么。我已经开始添加拆分到下面的linq查询,但这是方法不断给我一个编译错误,如:



参数1:无法转换为'string [ ]'到'字符串' - > 错误



更新代码:

< pre lang =c#> public ActionResult Search( string search,字符串类型,字符串封面,字符串 sin,字符串 cus)
{
DateTime昨天= DateTime.Today.AddBusinessDays(-1);

var query = 来自 s in db.data_qy
其中 s.UploadDate ==昨天
选择(s);

if (!String.IsNullOrEmpty(cover))
{
query = query.Where(s = < span class =code-keyword>> s.Cover == cover);
}

if (!string.IsNullOrEmpty(cus))
{
string [] ids = cus.Split(' ,' );

query = query.Where(c = > c.TAG.Contains(ids) ); // 错误
}
// var data = query.ToList();
return 查看(查询);
}



非常感谢任何帮助。非常感谢。

解决方案

更改

  string  ids = cus.Split( ' ,'); 



  string  [] ids = cus.Split(' ); 


Dear all,

I am trying to get my query, to be able to search multiple values of 'tag' fieldname in one textbox. I am little unclear what is correct approach for this task. I have started by adding split to the linq query below, however this is approach keeps throwing me a compiling error such as:

Argument 1: cannot convert from 'string[]' to 'string' --> error

Updated Code:

public ActionResult Search(string search, string type, string cover, string sin, string cus)
{
    DateTime yesterday = DateTime.Today.AddBusinessDays(-1);

    var query = from s in db.data_qy
               where s.UploadDate == yesterday
               select (s);

    if (!String.IsNullOrEmpty(cover))
    {
        query = query.Where(s => s.Cover == cover);
    }

    if (!string.IsNullOrEmpty(cus))
    {
        string [] ids = cus.Split(',');

        query = query.Where(c => c.TAG.Contains(ids)); //error
    }
   // var data = query.ToList();
    return View(query);
}


Any help would be very much appreciated. Many thanks.

解决方案

Change

string ids = cus.Split(',');


string [] ids = cus.Split(',');


这篇关于在文本框中搜索多个值 - mvc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆