Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
3
Reply
IList does not contain a definition for where, treeview MVC
Mani Kandan
Jan 6 2017 12:25 AM
360
Reply
Hello everyone,
In MVC 4, How can I generating a treeview with recursive partial view ?
This is the sql database treeview structure.
I have tried,
namespace
Reboxwebapp.Models.ViewModel
{
public
class
ProductCategoryVM
{
public
int
idProductCategory {
get
;
set
; }
public
string
ProductCategoryName {
get
;
set
; }
public
string
ProductCategoryDescription {
get
;
set
; }
public
Nullable<
int
> idParentCategoryProduct {
get
;
set
; }
public
string
AlternateNamesToSearch {
get
;
set
; }
public
Nullable<
int
> LevelID {
get
;
set
; }
public
string
CompletePathName {
get
;
set
; }
public
byte
[] PCImage {
get
;
set
; }
}
public
class
SeededProductCategies
{
public
int
? Seed {
get
;
set
; }
public
IList<ProductCategoryVM> Categories {
get
;
set
; }
}
}
[HttpGet]
public
ActionResult GetSearchProduct()
{
ProductsBIL objProduct =
new
ProductsBIL();
IList<ProductCategoryBL> lsRes =
new
List<ProductCategoryBL>();
lsRes = objProduct.GetProductCategoryTree();
IList<ProductCategoryVM> categories =
new
List<ProductCategoryVM>();
// ProductCategoryVM objProductCategoryVM = new ProductCategoryVM();
// categories = lsRes;
foreach
(var item
in
lsRes)
{
categories.Add(
new
ProductCategoryVM {idProductCategory =item.idProductCategory,idParentCategoryProduct = item.idParentCategoryProduct,ProductCategoryDescription = item.ProductCategoryDescription });
}
SeededProductCategies objSeededProductCategies =
new
SeededProductCategies { Seed =
null
, Categories = categories };
return
View(objSeededProductCategies);
}
GetSearchProduct
actionresult go to view is shown below,
@model Reboxwebapp.Models.ViewModel.SeededProductCategies
@Html.Partial("_TreeCategories", Model)
then partial view,
@model Reboxwebapp.Models.ViewModel.SeededProductCategies
@if (Model.Categories.Where(
s
=
>
s.idParentCategoryProduct
== Model.Seed).Any()) /*But here is occurring error : ilist does not contain a definition for where cause*/
{
<
ul
>
@foreach (var node in Model.Categories)
{
if (
node.idParentCategoryProduct
== Model.Seed)
{
Reboxwebapp.Models.ViewModel.SeededProductCategies
inner
=
new
Reboxwebapp.Models.ViewModel.SeededProductCategies {
Seed
=
node
.idProductCategory,
Categories
=
Model
.Categories };
<
li
>
<
a
href
=
"
[email protected]
"
>
@node.ProductCategoryDescription
</
a
>
@Html.Partial("_TreeCategories", inner)
</
li
>
}
}
</
ul
>
}
How can I do this? Please help me.
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
3
)
Next Recommended Forum
grid view controls
How to Pass Eval value to if statement in aspx page?