帮助asp.net mvc和选择列表下拉列表

时间:2022-11-12 00:21:14

I want to build this dropdowns with these specific attributes.. How can I do this? Im using LinqToSql. Each Company has employees

我想用这些特定属性构建这个下拉列表..我该怎么做?我使用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>

Do I have to build my own helper? please help. this all comes from Database and I have Company and Employee with LINQTOSQL classes

我必须建立自己的帮手吗?请帮忙。这一切都来自数据库,我有公司和员工使用LINQTOSQL类

2 个解决方案

#1


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...

据我所知是的...默认的html帮助器不能让你在选项上设置标题或类属性...

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.

如果你自己构建自己,我会使用lambda(匿名linq委托)来捕获/定义你所选择的属性。这样你就可以一遍又一遍地重复使用它。如果您需要帮助,请告诉我。

#2


0  

In asp.net MVC you already have a lot of built in Helpers. For the dropdown I would do something like this :

在asp.net MVC中,你已经拥有了很多内置的Helpers。对于下拉列表,我会做这样的事情:

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

<%= Html.DropDownList(“ ”,“ ”,new {@class =“ ”,title =“ ”})%></p>

#1


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...

据我所知是的...默认的html帮助器不能让你在选项上设置标题或类属性...

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.

如果你自己构建自己,我会使用lambda(匿名linq委托)来捕获/定义你所选择的属性。这样你就可以一遍又一遍地重复使用它。如果您需要帮助,请告诉我。

#2


0  

In asp.net MVC you already have a lot of built in Helpers. For the dropdown I would do something like this :

在asp.net MVC中,你已经拥有了很多内置的Helpers。对于下拉列表,我会做这样的事情:

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

<%= Html.DropDownList(“ ”,“ ”,new {@class =“ ”,title =“ ”})%></p>