如何在mvc razor视图中动态添加复选框 [英] how to add check box dynamically in mvc razor view

查看:171
本文介绍了如何在mvc razor视图中动态添加复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我想要显示名称列表,并且在那边附近一个复选框将是



假设名字列入名单



alex

raj

joseph

jena



所以我的输出将来



checkbox1 alex

checkbox2 raj

checkbox3 joseph

checkbox4 jena

here i want to diplay list of name and near that side one check box will be thre

suppose names are coming in a list

alex
raj
joseph
jena

so my output will come

checkbox1 alex
checkbox2 raj
checkbox3 joseph
checkbox4 jena

推荐答案

Pass your list as a parameter to the view using ViewBag
and then in the view:
@foreach(string list in ViewBag.List)
{
@Html.CheckBox("chbxName");@list.ToString();
<br/>
}
//You can create an integer variable and increment its value for each loop and append it to your checkbox control as its name.


这篇关于如何在mvc razor视图中动态添加复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆