Here is a simple solution.
Not everything needs to be written using the extension method in .NET code. One of the great features of MVC is its easy access to create your own HTML.
With MVC4, you can get the identifier and name of an element in the expression tree using the HTML.NameFor and HTML.IdFor
<select name="@Html.NameFor(Function(model) model.CityId)" id="@Html.IdFor(Function(model) model.CityId)" class="location_city_input"> @For Each city In Model.Cities @<option value="@city.Value" @(If(city.Value = Model.CityId, "selected", "")) data-geo-lat="@city.Lat" data-geo-lng="@city.Lng" data-geo-zoom="@city.Zoom"> @city.Text </option> Next </select>
Assuming Model.Cities is a collection of elements that expose each of these properties. Then you must be tuned.
If you want reuse, consider making it an editor template for everything that is enumerable from cities
KyleMit Dec 31 '15 at 20:00 2014-12-31 20:00
source share