asp.net-mvc - 为什么 Id 列没有出现在 MVC5 的 CSHTML 视图中
问题描述
我正在研究 MVC5 项目-代码首先,在我的模型中,第一个方法是 Id 方法(键),当我创建视图(列表、创建、详细信息和删除模板)时,id 方法没有标题单元格,但我的模型中的所有其他方法都有。
这是我的模型:
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
[Required(ErrorMessage = "First Name is required ")]
public string First_Name { get; set; }
[Required(ErrorMessage = "Last Name is required ")]
public string Last_Name { get; set; }
public string Birth_Date { get; set; }
[Required(ErrorMessage = "Room Number is required ")]
public int Room_Number { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime Check_In_Date { get; set; }
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime Check_Out_Date { get; set; }
[Required(ErrorMessage = "Number Of Adults required ")]
public int Number_Of_Adults { get; set; }
public Decimal Advanced_Payment { get; set; }
}
我的控制器是:
public ActionResult Index()
{
return View(db.controlPanels.ToList());
}
[HttpGet]
public ActionResult Create()
{
return View(new ControlPanel());
}
[HttpPost]
public ActionResult Create(ControlPanel controlPanel)
{
if (ModelState.IsValid)
{
db.controlPanels.Add(controlPanel);
db.SaveChanges();
return RedirectToAction("Index");
}
else
{
return View(controlPanel);
}
}
我的观点是:
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.First_Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Last_Name)
</th>
<th>
@Html.DisplayNameFor(model => model.Birth_Date)
</th>
<th>
@Html.DisplayNameFor(model => model.Room_Number)
</th>
<th>
@Html.DisplayNameFor(model => model.Check_In_Date)
</th>
<th>
@Html.DisplayNameFor(model => model.Check_Out_Date)
</th>
<th>
@Html.DisplayNameFor(model => model.Number_Of_Adults)
</th>
<th>
@Html.DisplayNameFor(model => model.Advanced_Payment)
</th>
<th></th>
</tr>
当我创建视图时,我需要 Id 列自动出现,就像其他列一样。你能告诉我正确的方法吗?
解决方案
推荐阅读
- c# - ProjectItem.Object 在某些情况下为空,无法运行自定义工具
- haskell - 如何在 Parsec 中返回多个解析的 ADT?
- reactjs - 文本在 react-admin 界面中无法正确显示
- mongodb - 如何访问 MongoDB 表中的元素?
- python - 使用“空格”字符导入 python 模块目录
- php - 从sql视图中选择时如何在laravel中修复“准备好的语句需要重新准备”
- java - 如何在线创建和验证 onedrive 或 sharepoint 的 webhook?
- json - REST API:更新 JSON 对象数组的最佳实践
- java - 在文件中的每个单词后添加空格(Java)
- python - 访问 Python 虚拟环境