Friday, 15 June 2012

asp.net - How can I add a class to this version of a dropdownlistFor? -



asp.net - How can I add a class to this version of a dropdownlistFor? -

there seem many different ways create dropdownlistfor. viewbags etc.

i've been trying different versions have problem adding "attributes" need. can't possible should have take whether want utilize distinct() or add together class dropdownlistfor.

please have @ this, how go adding class this:

@html.dropdownlistfor(model => model.catdroptemp, model.categories.distinct().select(kat => new selectlistitem { text = kat, value = kat }), "----choose----")

look @ overload of dropdownlistfor. has params using plus additional one, object htmlattributes. how assign arbitrary html attributes resulting tag. if wanted someattribute, pass new object { someattribute = "value" }.

now class bit different since key word in c#. class should precede @. this:

@html.dropdownlistfor( model => model.catdroptemp, model.categories.distinct().select(kat => new selectlistitem { text = kat, value = kat }), "----choose----", new object { @class = "theclass" })

asp.net dropdownlistfor

No comments:

Post a Comment