0

As part of my search page I am allowing the user to make a multi-select on specific search terms using the KendoUI Multiselect widget. These items in the collection are passed to my controller as a parameter. My question is, after I have passed them to my controller how do I use them? more specifically how do I use them in my Where statement which uses the Contains method.

Here is my code for the multi select widget

@(Html.Kendo().MultiSelect() .Name("vessel_type") .Placeholder("Select Type") .BindTo(new List<string>() { "AHTS", "PSV", "Special" })) 

Here is my controller code which uses the vessel_type as a parameter

public ActionResult Search(IEnumerable<string> vessel_type) { var vessels = (from o in db.vessels select o); vessels = vessels.Where(s => s.vessel_type.Contains(vessel_type)); return PartialView("_results", vessels); } 

This line isn't correct because it's expecting a string but I have a collection of mroe than one:

 vessels = vessels.Where(s => s.vessel_type.Contains(vessel_type)); 

Thanks

1
  • What is the type of s.vessel_type? Commented Aug 4, 2016 at 14:40

1 Answer 1

2

If I understand the question correctly, I believe you need to perform the check the other way around, that is check if the vessel_type collection contains the vessel's type:

vessels = vessels.Where(s => vessel_type.Contains(s.vessel_type)); 

Here Contains is an extension method on IEnumerable<T>.

On a side note, since the parameter represents a collection, I think a plural name is more appropriate, for example vessel_types.

Sign up to request clarification or add additional context in comments.

1 Comment

Ahh yes understood, thanks for that it works perfectly.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.