来自数据库的 ASP.Net MVC 3 CheckBoxList
我有一个名为的表
tb_role
id role
1 admin
2 user
3 viewer
,视图如下:
<div style="width:50%; float:right;">
<legend>User Role</legend>
<table>
<tr>
<th>Role</th>
</tr>
<tr>
<td align="center"><input type="checkbox" id="CBRole"/></td>
</tr>
</table>
</div>
我想问,如何从表中列出我的复选框(CBRole)?所以我的 CBRole 从我的表中列出。
非常感谢
编辑
假设我有这样的角色表:
tb_role
RoleId Role_Name
1 SalesCreate
2 SalesEdit
3 AgentCreate
4 AgentEdit
我想在复选框中列出销售角色(SalesCreate 和 SalesEdit,所以它只有 2 个复选框),该怎么做? 谢谢
i have a table called
tb_role
id role
1 admin
2 user
3 viewer
and for the View is like this :
<div style="width:50%; float:right;">
<legend>User Role</legend>
<table>
<tr>
<th>Role</th>
</tr>
<tr>
<td align="center"><input type="checkbox" id="CBRole"/></td>
</tr>
</table>
</div>
I want to ask, how to list my checkbox(CBRole) from my table? so my CBRole is listed from my table.
thanks a lot
EDIT
assumed that i have Roles table like this :
tb_role
RoleId Role_Name
1 SalesCreate
2 SalesEdit
3 AgentCreate
4 AgentEdit
i want to list role for Sales in checkbox (SalesCreate and SalesEdit, so its only have 2 checboxes), how to do that ?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从您的控制器中,您可以使用以下属性填充您的视图模型:
您的 RoleViewModel
从处理 Get 调用的控制器(例如 /roles/edit/1 )
执行类似的操作
然后在您的视图中(在表单标记内),您将在控制器中 回答 Post 部分,您将访问 RolesSelected 并检查 ID。
在示例中,我放置了一个 div,但您显然可以将其更改为您喜欢的内容。希望有帮助
From your controller you populate your view model with these properties:
Your RoleViewModel
From controller that handles the Get call (/roles/edit/1 for example)
then in your view (inside a form tag) you will do something like this
in the controller that answer the Post part you will access the RolesSelected with the IDs checked
In the example I have put a div, but yuo can change it to what you like obviously. Hope it helps
您可能想要类似于 StackOverflow 上的以下帖子的内容,Enum to CheckBox
You probably want to have something that looks like the following post on StackOverflow, Enum to CheckBox