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.
I can set the view, like this:
@Html.ListBoxFor(model => model.IdState, null, new { size = "7" })
But I don’t know how to change the controller from:
public ActionResult Index(FormData model)
{
IQueryable<mytable> results = from s in db.mytable.Include("State").where(s=> (model.IdState != null ? s.IdState == model.IdState : true)) select s;
return View(result);
}
To a multiple IdState Result???
Earlier the IdState was:
int IdState;
Now is:
IEnumerable<int> IdState;
Thanks for your time!
I still can’t make it work. In SQL will be:
SELECT * FROM MyTable WHERE IdState IN (1,2,5,7,10)
Any Idea? The http://msdn.microsoft.com/en-us/vcsharp/aa336746.aspx Don’t show similar situation
Workaround
I found on this discussion: http://social.msdn.microsoft.com/forums/en-US/adodotnetentityframework/thread/095745fe-dcf0-4142-b684-b7e4a1ab59f0/ this code snippet:
IQueryable<Foo> foos = context.Foo.Where("it.Id in {1, 2, 3, ...}");
I changed to
string sState = "";
foreach (int a in model.IdState ) sState += (a.ToString() + ",");
sState = sState .Substring(0, sState .Length - 1);
IQueryable<mytable> results = from s in db.mytable.Where("it.IdState in {" + sState + "}");
And It works great!!!
I hope can find the final solution
Instead of
try using