Does the mvc3 razor engine support listing from List.ForEach ()

I have 2 blocks of code, first:

@foreach(var filterName in Model.FilterNames){
    <text>
        $("#@filterName").combobox({
            source:"@(filterName)Autocomplete"
        });
    </text>
}

second:

@Model.FilterNames.ForEach(filterName => {
    <text>
        $("#@filterName").combobox({
            source:"@(filterName)Autocomplete"
        });
    </text>
})

The second one does not work. Does anyone know if razor supports this syntax? Or what am I doing wrong?

+3
source share
2 answers

When using the method in a razor, it will assume that it is an assistant or property and returns either HelperResult or data.

Since the List.ForEach method does not return anything, the call will fail.

+2
source

ForEach - List<T> , IEnumerable<T> (, , @using System.Collections.Generic / ), ( ) .

.

.

+1

Source: https://habr.com/ru/post/1789705/


All Articles