I have a class that has a IEnumerable<SelectListItem>
as one of its properties. I'm using this list to populate a @Html.DropDownListFor()
Drop down list - this is working and I am getting the values I expect in my dropdown.
However I want to modify the text value that shows in the drop down list.
I think one way to do this would be to modify the value in the Getter something like this:
public IEnumerable<SelectListItem> ShippingQuotes
{
get { return ShippingQuotes; }//SomethingHere to modify the text property of the Select List Items;
set { ShippingQuotes = value; }
}
Can someone help me with the syntax here?
You can simply modify its text using Select()
:
public IEnumerable<SelectListItem> ShippingQuotes
{
get { return shippingQuotes.Select(x => {x.Text = "Some Text" + x.Text; return x;}); }
set { ShippingQuotes = value; }
}