Search code examples
html-helperc#-to-vb.net

Converting C# Razor view syntax for checkboxlist into VB.Net


Here is the HTML code for "CheckBoxListFor" which I copied from "http://www.codeproject.com/Articles/292050/CheckBoxList-For-a-missing-MVC-extension" Could you please help me out in converting this C# code into VB.Net?

@Html.CheckBoxListFor(model => model.PostedCities.CityIDs, 
                      model => model.AvailableCities, 
                      entity => entity.Id, 
                      entity => entity.Name, 
                      model => model.SelectedCities)

Solution

  • @Html.CheckBoxListFor(Function(model) model.PostedCities.CityIDs, _
                          Function(model) model.AvailableCities, _
                          Function(entity) entity.Id, _
                          Function(entity) entity.Name, _
                          Function(entity) If(Model.SelectedCities Is Nothing, False, Model.SelectedCities.Contains(entity.Id)),
    htmlListInfo, Function(htmlAttribute) New With {.class = "chkBoxList"})