asp.net mvc 4 - KnockoutMVC Foreach Lambda filter (or any filter) -


i have been able create display loops list of pages. display pages in db table following.

@using (var page = ko.foreach(m => m.pagelist)) {     @page.html.textbox(p => p.pageerrormessage)     @page.html.textbox(p => p.pagesuccessmessage)     @page.html.textbox(p => p.title)     @page.html.textbox(p => p.content) } 

i able filter displays lambda expression on foreach. returns type ienumerable, tolist() @ end following not work.

//note: have tried .where pl.title == "string" same results @using (var page = ko.foreach(m => m.pagelist.where(pl => pl.title.contains("page01"))) {     @page.html.textbox(p => p.pageerrormessage)     @page.html.textbox(p => p.pagesuccessmessage)     @page.html.textbox(p => p.title)     @page.html.textbox(p => p.content) } 

i can results want, seems cumbersome this. if add visible check each field same check see fields want.

//note: p.title.contains("string") not work me in visible here @using (var page = ko.foreach(m => m.pagelist)) {     @page.html.textbox(p => p.pageerrormessage).visible(p => p.title == "page01!")     @page.html.textbox(p => p.pagesuccessmessage).visible(p => p.title == "page01!")     @page.html.textbox(p => p.title).visible(p => p.title == "page01!")     @page.html.textbox(p => p.content).visible(p => p.title == "page01!") } 

is there better way work foreach filter down list or designed return full set?

you cannot use c# code in razor modify viewmodel. bind against needs representation in viewmodel. if want filter full list, computed property on viewmodel should trick.

[computed] public list<page> filteredlist {   { return pagelist.where(pl => pl.title.contains("page01")); } } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -