简体   繁体   中英

Nonfactors MVC Grid Ternary operator fails

I'm using the great NonFactor MVC Grid with quite a bit of success, but I am seeing a weird issue:

@(Html
    .Grid(items)
    .Build(columns =>
    {
        columns.Add(model => model.Type).Formatted("{0}" == "folder" ? "<span class=\"glyphicon glyphicon-folder-open\"></span>" : "<span class=\"glyphicon glyphicon-file\"></span>").Encoded(false);
        columns.Add(model => model.Id).Titled("Id");
        columns.Add(model => model.Name).Titled("Name");
        columns.Add(model => model.Size).Titled("Size");
    })
    .Empty("No data found")
    .Sortable()
)

Here, if the row's property Type is equal to folder , its should display the folder icon in that column. However I'm finding that the 2nd option is always used for that Formatted column.

so if I switch the options around for that ternary operator, then the folder icon is always displayed, where currently the file icon is always displayed.

Does anyone know why that is happening, and if there is a way of overcoming this?

I ended up just doing this instead

@(Html
    .Grid(items)
    .Build(columns =>
    {
        columns.Add(model => model.Type).Formatted("<span class=\"glyphicon glyphicon-{0}-open\"></span>").Encoded(false);
        columns.Add(model => model.Type).Titled("Type").Css("hidden");
        columns.Add(model => model.Id).Titled("Id");
        columns.Add(model => model.Name).Titled("Name");
        columns.Add(model => model.ModifiedDate).Titled("Modified");
        columns.Add(model => model.longSize).RenderedAs(model => model.Size).Titled("Size");
        // columns.Add(model => model.mbSize).Titled("Size (MB)");
    })
    .Empty("No data found")
    .Sortable()
    .RowCss(model => "rowStyle")
)

So the line

columns.Add(model => model.Type).Formatted("<span class=\"glyphicon glyphicon-{0}-open\"></span>").Encoded(false);

Will show a folder icon if its a folder, and nothing if its a file (since glyphicon-file-open is not a valid icon class)

Not the best solution as there is not icon for files now, but its good enough.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM