How to change id value when using Html.DropDownListFor helper in asp.net mvc 2.0?

前端 未结 2 1914
暗喜
暗喜 2021-02-19 00:49

I have a partial view that has something like this

 <%= Html.DropDownListFor(m => m.SelectedProductName, Model.ProductList, \"Select a Product\") %>
         


        
2条回答
  •  北海茫月
    2021-02-19 01:13

    I can't find the documentation at the moment, but there is an overload for DropDownListFor that will accept an object-typed collection of attributes (HtmlAttributes is the parameter name.)

    It will look something like this:

    Html.DropDownListFor(model=>model.SomeProperty, new {@id="UniqueID1234"});
    

    You can use Intellisense to find the overload that includes HtmlAttributes.

提交回复
热议问题