私のコントローラでは、ユーザーが渡した指定のクエリ文字列に基づいて条件をテストする必要があります。asp.netのクエリ文字列による動的linqクエリmvc c#
string dep = Request.QueryString["dep"];
string cat = Request.QueryString["cat"];
string brand = Request.QueryString["brand"];
string search = Request.QueryString["search"];
if(!string.IsNullOrEmpty(dep) && !string.IsNullOrEmpty(search))
//does the GetDepSearch() method
}
if(!string.IsNullOrEmpty(dep) && !string.IsNullOrEmpty(brand)){
//does the GetDepBrand() method
}
if(!string.IsNullOrEmpty(cat) && !string.IsNullOrEmpty(search)){
//does the GetCatSearch() method
}
if(!string.IsNullOrEmpty(cat) && !string.IsNullOrEmpty(brand)){
//does the GetCatBrand() method
}
if(!string.IsNullOrEmpty(dep) && !string.IsNullOrEmpty(cat) &&
!string.IsNullOrEmpty(search)){
//does the GetDepCatSearch() method
}
if(!string.IsNullOrEmpty(dep) && !string.IsNullOrEmpty(cat) &&
!string.IsNullOrEmpty(brand)){
//does the GetDepCatBrand() method
}
if(!string.IsNullOrEmpty(dep) && !string.IsNullOrEmpty(cat) &&
!string.IsNullOrEmpty(brand) && !string.IsNullOrEmpty(search)){
//does the GetDepCatBrandSearch() method
}
if(!string.IsNullOrEmpty(search) && !string.IsNullOrEmpty(brand)){
//does the GetSearchBrand() method
}
if(!string.IsNullOrEmpty(dep) && !string.IsNullOrEmpty(search) &&
!string.IsNullOrEmpty(brand)){
//does the GetDepSearchBrand() method
}
if(!string.IsNullOrEmpty(cat) && !string.IsNullOrEmpty(search) &&
!string.IsNullOrEmpty(brand)){
//does the GetCatSearchBrand() method
}
私はそのようにそれを行うことは非常に困難である知っている:
これらは、私は現在テストしてるの条件があります。私が望むのは、コントローラーからの指定された照会ストリングに基づいて条件に一致するモデル内のデータを照会するメソッドを使用して結果を得ることです。
これをDynamic LinQまたはこれ以外のものに置き換える必要がありますか?私はDynamic LinQについて本当に知りません。
すべてのあなたの答えにようこそ、ありがとうございます。
おかげでジム。あなたのリンクに見られるように、私は自分のコントローラーでこのメソッドを使用する方法を知ることができません。それについて少し説明していただけますか? – titi