title: asp.net mvc 3 EF HTML MultiSelect - How to retrieve multiple values using LINQ
body: <p>I have an Advanced Search form, It contains, input boxes, dropdown lists, etc. And now I want to change a dropdown list to a multiselect list.</p>
  
  <p>I can set the view, like this:</p>
  
  <pre><code>@Html.ListBoxFor(model =&gt; model.IdState, null, new { size = "7" })
  </code></pre>
  
  <p>But I don't know how to change the controller from:</p>
  
  <pre><code>public ActionResult Index(FormData model)
  {
      IQueryable&lt;mytable&gt; results = from s in db.mytable.Include("State").where(s=&gt; (model.IdState != null ? s.IdState == model.IdState : true)) select s;
      return View(result);
  }
  </code></pre>
  
  <p>To a multiple IdState Result???</p>
  
  <p>Earlier the IdState was:</p>
  
  <pre><code>int IdState;
  </code></pre>
  
  <p>Now is:</p>
  
  <pre><code>IEnumerable&lt;int&gt; IdState;
  </code></pre>
  
  <p>Thanks for your time!</p>
  
  <p><strong>I still can't make it work. In SQL will be:</strong></p>
  
  <pre><code>SELECT * FROM MyTable WHERE IdState IN (1,2,5,7,10)
  </code></pre>
  
  <p>Any Idea? The <a href="http://msdn.microsoft.com/en-us/vcsharp/aa336746.aspx" rel="nofollow">http://msdn.microsoft.com/en-us/vcsharp/aa336746.aspx</a> Don't show similar situation</p>
  
  <p><strong>Workaround</strong></p>
  
  <p>I found on this discussion: <a href="http://social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/thread/095745fe-dcf0-4142-b684-b7e4a1ab59f0/" rel="nofollow">http://social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/thread/095745fe-dcf0-4142-b684-b7e4a1ab59f0/</a> this code snippet:</p>
  
  <pre><code>IQueryable&lt;Foo&gt; foos = context.Foo.Where("it.Id in {1, 2, 3, ...}");
  </code></pre>
  
  <p>I changed to</p>
  
  <pre><code>string sState = "";
  foreach (int a in model.IdState ) sState += (a.ToString() + ",");
  sState = sState .Substring(0, sState .Length - 1);
  IQueryable&lt;mytable&gt; results = from s in db.mytable.Where("it.IdState in {" + sState + "}");
  </code></pre>
  
  <p>And It works great!!!</p>
  
  <p>I hope can find the final solution</p>