我正在创建 Mvc 3 razor databasefirst 应用程序。为此,我有 Tblskills 表和 TblEmployeeDetails。我想在创建页面的数据库中的复选框中显示技能。
控制器
public ActionResult Create() {
List<TblSkill> Skills = EmployeeMVC.Infrastructure.HtmlHelpers.GetTblSkill().ToList();
ViewBag.skill = new List<TblSkill>(HtmlHelpers.GetTblSkill());
return View();
}
创建视图
@{
List<EmployeeMVC.Models.TblSkill> Skills = ViewBag.skill;
for (int i = 0; i < Skills.Count; i++)
{
Response.Write("<td style='border: none;'>");
Response.Write(string.Format("<input type='checkbox' id='skill{0}' name='skill' value='{0}' {2}/><label for='skill{0}'>{1}</label><br/>",
Skills[i].SkillsId, " " + Skills[i].Skills + " ",
(EmployeeMVC.Infrastructure.HtmlHelpers.GetTblSkill())
));
Response.Write("</td>");
if ((i + 1) % 3 == 0)
{
Response.Write("</tr><tr>");
}
}
}
并在 GetTblSkill 方法中
public static IQueryable<TblSkill> GetTblSkill()
{
return (from x in db.TblSkills
select x);
}
我没有在开始页面中显示的技能字段中获得复选框