Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Casting DynamicList #6

Open
hajerkr opened this issue May 26, 2021 · 1 comment
Open

Casting DynamicList #6

hajerkr opened this issue May 26, 2021 · 1 comment

Comments

@hajerkr
Copy link

hajerkr commented May 26, 2021

Hi @cesarsouza. I've been working with the 1.3.4 version for .NET 3.1 and everything is going well. One question (which is not so much of an issue but an inquiry, not sure where to ask if not here!), is there an easy way to cast a DynamicList <DynamicListItem> to a ICollection, or do I have to loop over it every time? As far as I can tell there is not a function in place; but please correct me if I am wrong. The functions such as AsIEnumerable, AsQueryable don't do that exactly I think.

@cesarsouza
Copy link
Member

cesarsouza commented May 28, 2021

Hi @hajerkr,

Thanks for the question! Unfortunately it is not possible to cast the list directly to an ICollection because if the DynamicList implemented the ICollection interface, this would confuse the default ASP.NET model binder during binding. This was actually something that I had added in v1.4 but now removed when I last updated it to v1.5 because it was causing issues.

If you would like to convert the list to a collection, I think the easiest way would be to use .ViewModels or .Options properties of the DynamicList, e.g.:

DynamicList<BookViewModel> books = new DynamicList<BookViewModel>();
var viewModels = books.ViewModel.ToList(); // to get a list of the view models, or
var listItems = books.Options.ToList(); // to get a list of the dynamic list items

Hope it helps!
Cesar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants