I want Add “Select Activity” values as first values of HTML dropdown, but when I add it is showing as last record in Drop down.
I want to show Default value as “Select Activity” in drop down.
I am using ASP.NET MVC3, code:
public SelectList GetSubContractorechniciansList(String subContractorId)
{
var s1 = GetSubContractorechnicians(subContractorId);
var result = s1.ToList().Select(d => new
{
Key = d.TECH_NUMBER,
Value = d.EMPLOYEE_TECH_NAME.ToString()
}).Distinct().ToDictionary(mc => mc.Key, mc => mc.Value);
result.Add("Select Activity", "Select Activity");
var selectItems = new SelectList(result, "Key", "Value");
return selectItems;
}
You do this when rendering the dropdown in your view:
or if against all good practices you don’t use a view model and rely on weakly typed ViewBag and helpers: