Binding 3 or more values to DropDownList

“Download” link can be generated by HTML5’s “a” tag with “download” attribute OR JavaScript code.

DropDown list (“<select>”) element can bind values only into its display texts and values.
In the following example, the dropdown list binds 3 values with using “#” as a delimiter in ASP.NET MVC.

Model

public class ListItem
{
    public string DisplayText { get; set; }
    public string ItemValue1 { get; set; }
    public string ItemValue2 { get; set; }
}

ViewModel

List<ListItem> Items { get; set; }

View


@Html.DropDownListFor(
    model => model.SomeVal, 
    new SelectList(Model.Items.Select(i => new { Text = i.DisplayText, Value = string.Concat(i.ItemValue1, "#", i.ItemValue2) }), 
    "Value", 
    "Text", 
    new { id = "dropdown" })
)

Getting the selected value1 and value2 in JavaScript: JSFiddle

var selected = $('#dropdown :selected').val();
var splited = selected.split("#");
var value1 = splited[0];
var value2 = splited[1];