当前位置: 动力学知识库 > 问答 > 编程问答 >

asp.net mvc 3 - how to use the array of values in the where clause of my query

问题描述:

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

}

}

In controller:

 public ActionResult SearchDetails( string model)

{

var query = (from ......).where();//want to compare array values in controller

}

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.

my array contains only integer values(id's),while debugging the when i put cursor at the parameter of action method the values are coming in "\"[{\\"id\\":1},{\\"id\\":2}]\"" format.can u tell me how to use this array of values in my where clause of my query.

网友答案:

if you are bound and determined to stick with the string input, I would think a call to Split would work. However, it would be much easier if you changed from bringing it in as a string to just bringing in the model. Have you tried something like:

  public ActionResult SearchDetails( model model)     
  {
     var query = (from ......).where();//want to compare array values in controller

  }

are you trying to do something equivalent to a SQL IN? If that is the case then use .Contains in your query. For example:

public ActionResult SearchDetails(model model)
{
    var query = from d in context.data
                where model.Contains(d.id)
                select d;
}
分享给朋友:
您可能感兴趣的文章:
随机阅读: