我正在创建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);
}
我没有收到复选框 技能字段显示在起始页面
中