1

これらの特定の属性を使用してこのドロップダウンを作成したい..どうすればよいですか? LinqToSql を使用しています。各企業には従業員がいます

<select name="companies" id="companies" class="selectable">
    <option value="">-- select --</option>
    <option value="1" title="company1">Company1</option>
    <option value="2" title="company2">company2</option>
    <option value="3" title="company3">company3</option>
    <option value="4" title="company4">company4</option>
</select>


<select name="employees" id="employees" class="selectable">
    <option value="">-- select --</option>
    <option value="1" class="company1">John</option>
    <option value="2" class="company1">michale</option>
    <option value="4" class="company2">brian</option>
    <option value="5" class="company2">mark</option>
    <option value="6" class="company3">daniel</option>
    <option value="7" class="company3">rose</option>
</select>

独自のヘルパーを作成する必要がありますか? 助けてください。これはすべてデータベースから来ており、LINQTOSQL クラスを持つ Company と Employee があります

4

2 に答える 2

1

As far as I know yes... The default html helper doesn't give you the ability to set the title or the class attribute on the options...

I would recommend building your own (or looking around to see if someone else has done one that solves this problem).

If you do build your own I would use lambda's (anonymous linq delegates) to capture/define the attributes your are after for the options. That way you can reuse it over and over. Let me know if you need help with this.

于 2010-02-01T20:26:07.393 に答える
0

asp.net MVC には、既に多くのヘルパーが組み込まれています。ドロップダウンの場合、次のようにします。

<%= Html.DropDownList("<name>", "<selectlist collection>", new { @class = "<css class>", title = "<title>" }) %>

于 2010-02-01T20:28:34.643 に答える