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

前端 未结 2 1915
暗喜
暗喜 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.

    0 讨论(0)
  • 2021-02-19 01:21

    You can use a hardcoded jQuery:

    $('select#[id of your select box]').attr('id', '[id that you want]');
    
    0 讨论(0)
提交回复
热议问题