My issue comes with the layers.Add part. I'm brand new to MVC, Razor, Linq and Telerik's KendoUI using the Map widget. the layers.Add() function gets a green squiggly line with message "Use lambda expression". Why am I getting this? Thanks for your help. link here
@(Html.Kendo().Map()
.Name("map")
.Center(39.6924, -97.3370)
.Zoom(4)
.Layers(layers =>
{
layers.Add()
.Style(style => style.Fill(fill => fill.Opacity(0.7)))
.Type(MapLayerType.Shape)
.DataSource(dataSource => dataSource
.GeoJson()
.Read(read => read.Url(Url.Content("~/Scripts/gz_2010_us_040_00_500k.js")))
);
})
.Events(events => events
.ShapeCreated("onShapeCreated")
.ShapeMouseEnter("onShapeMouseEnter")
.ShapeMouseLeave("onShapeMouseLeave")
)
)
The IDE is simply suggesting that you could shorten your lambda. Suppose F
is some function that returns void. Then both of the following are the same:
x => { F(x); }
x => F(x)
So your code could be shortened by replacing this:
layers =>
{
layers.Add()
.Style(style => style.Fill(fill => fill.Opacity(0.7)))
.Type(MapLayerType.Shape)
.DataSource(dataSource => dataSource
.GeoJson()
.Read(read => read.Url(Url.Content("~/Scripts/gz_2010_us_040_00_500k.js")))
);
}
With this:
layers => layers.Add()
.Style(style => style.Fill(fill => fill.Opacity(0.7)))
.Type(MapLayerType.Shape)
.DataSource(dataSource => dataSource
.GeoJson()
.Read(read => read.Url(Url.Content("~/Scripts/gz_2010_us_040_00_500k.js")))
)
For legibility reasons you may or may not want to actually make this change.