Link to home
Start Free TrialLog in
Avatar of lulu50
lulu50Flag for United States of America

asked on

Error cannot convert string[] to string

Hi,

I'm getting an error that says " Cannot convert string[] to string " 

My data in the database for the commitID field looks like this:

CommitID 
29384484, 35283847, 44757583
48475739
85757573, 95857374
75757573

Open in new window



...but, my dropdown list has the list as a string[]:

29384484
35283847
44757583
48475739
85757573
95857374
75757573

Open in new window


My dropdown list is on the search page to filter the data but I'm not getting any data right after the commitID code not able to filter the data:

if (model.SelectedCommitID != null)
   list = list.Where(x => x.CommitID.Contains(model.SelectedCommitID));    //I get an error here that says "cannot convert string[] to string"

Open in new window



I tried any() or put the model.SelectedCommitID in a list but it did not work either. These are all my failing trials:

//Filter Commit ID
// if (model.SelectedCommitID != null)
//   {
//     List<string> stringlist = new List<string>();
//   stringlist.Add(model.SelectedCommitID.ToString());
// list = list.Where(x => x.CommitID.Contains(stringlist.ToString()));
// }


//   list = list.Where(x => x.CommitID.Contains(model.SelectedCommitID));   (Did not work)
//list = list.Where(x => x.CommitID.Contains(model.SelectedCommitID.ToString()));     (Did not work) 
//list = list.Where(x => model.SelectedCommitID.Any(m => Equals(x.CommitID.ToString(), m)));     (Did not work)
//list = list.Where(x => x.CommitID.Contains(model.SelectedCommitID.ToString()));    (Did not work)

Open in new window

Avatar of kaufmed
kaufmed
Flag of United States of America image

Add a ToArray call after your Where:

list = list.Where(x => x.CommitID.Contains(model.SelectedCommitID))
           .ToArray();

Open in new window

What are the types for each of these:

SelectedCommitID
list
CommitID

-saige-
Avatar of lulu50

ASKER

public string[] SelectedCommitID { get; set; }

database table RuleDetail

CommitID      varchar(1000)
Avatar of lulu50

ASKER

IEnumerable<CABR_RuleDetail> list = new List<CABR_RuleDetail>();
       

   
                list = _unitOfWorkCABusinessRules.RuleDetailRepo.GetAll().ToList();
ASKER CERTIFIED SOLUTION
Avatar of it_saige
it_saige
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lulu50

ASKER

wow!!!!
 
it's working!!!!!

saige Thank you !!!!

Wow wow

Thank you
Thank you
Thank you
one more
Thank you
Avatar of lulu50

ASKER

saige,

wow Great work!!!

Thank you
Glad to help