有关 asp.net mvc 和选择列表下拉菜单的帮助
我想用这些特定属性构建这个下拉菜单。我该怎么做?我正在使用 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 类的公司和员工
I want to build this dropdowns with these specific attributes.. How can I do this? Im using LinqToSql. Each Company has employees
<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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知是的...默认的 html 帮助器无法让您在选项上设置标题或类属性...
我建议构建您自己的(或者环顾四周看看其他人是否有做了一个解决这个问题的方法)。
如果您确实构建自己的,我将使用 lambda(匿名 linq 委托)来捕获/定义您想要的选项属性。这样你就可以一遍又一遍地重复使用它。如果您需要这方面的帮助,请告诉我。
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.
在 asp.net MVC 中,您已经有很多内置的帮助程序。对于下拉列表,我会执行以下操作:
<%= Html.DropDownList("", "", new { @class = "", title =“<标题>”})%>
In asp.net MVC you already have a lot of built in Helpers. For the dropdown I would do something like this :
<%= Html.DropDownList("<name>", "<selectlist collection>", new { @class = "<css class>", title = "<title>" }) %>