Used List<string> as Model in Web Grid at ASP.NET MVC3

asp.net-mvc-3, razor, webgrid

Solution

That is weird, but the explanation is that the WebGrid looks for public properties of the row objects in order to display them as columns; it just so happens that Length is the only property that type String exposes.

Note that you can get your desired behavior by specifying the format explicitly:

@grid.GetHtml(
    columns: new[] {
        g.Column(format: (item) => item)
    }
)

Problem

I passed List as Model to WebGrid Constructor. `@model List<string>` `@{ var grid = new WebGrid(Model); }` `<div> @grid.GetHtml() </div>` I am expecting to get my List of string with grid. But I got length of string. Weird?

Original source