如何在lambda表达式的where子句中使用值的数组 [英] how to use the array of values in the where clause of lambda expression
本文介绍了如何在lambda表达式的where子句中使用值的数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用asp.net mvc3.
我想使用parameterMap将数组从视图传递到控制器,如下所示
我认为:
I am using asp.net mvc3.
I want to pass an array from view to the controller using parameterMap as shown below
In my view:
parameterMap:
function (data, options) {
if (options === "read") {
sessionStorage.setItem("value","array");
val = sessionStorage.getItem("value"); // contains array
return { model: JSON.stringify(val) };//passing array to controller
}
}
控制器:
controller:
public ActionResult SearchDetails( string model)
{
var query = (from ......).where();
}
但是我无法在控制器中检索这些值.您能告诉我如何在不使用循环语句的情况下在控制器中检索这些值数组吗?我想在查询的where子句中使用这些值. >
您能告诉我该怎么做吗?
but i am not able to retrieve those values in the controller.can u tell me how to retrieve these array of values in my controller with out using looping statements.and i want to use these values in where clause in my query.
can u tell me how to do this
推荐答案
您不要在where
子句中使用 array -您可以使用单个元素.
表格是
You don''t use the array in thewhere
clause - you use an individual element.
The form is
var query = from element in someArray
where SomePredicate(element)
select SomeSelection(element);
...
例如
E.g.
var values = from e in model.Split(',')
where e.Contains("=")
select e.Split('=')[1];
...
您可能需要咨询在C#中使用LINQ入门 [
You may need to consult Getting Startet with LINQ in C#[^].
Cheers
Andi
这篇关于如何在lambda表达式的where子句中使用值的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文