我想在复选框旁边显示手机的名称。因此,我将以下代码与 EditorForModel 一起使用,但它仅在12中呈现。我不明白为什么它显示 12 而不是手机名称。
我已经使用 Ado.net 实体模型从数据库表Mobile生成模型类。所以我有一个名为 Mobile.cs 的模型类
namespace MvcDropdown.Models
{
using System;
using System.Collections.Generic;
public partial class Mobile
{
public int Model { get; set; }
public string Type { get; set; }
public string Cost { get; set; }
public Nullable<bool> IsSelected { get; set; }
}
}
在 HomeController 中,我有一个动作方法
public ActionResult checkboxfun()
{
GadgetsContext gc = new GadgetsContext();
return View(gc.Mobiles);
}
现在我通过将视图命名为 Mobile 来使用编辑器模板,如下所示。
@model MvcDropdown.Models.Mobile
@Html.HiddenFor(m=>m.Model)
@Html.HiddenFor(m=>m.Type)
@Html.EditorFor(m=>m.IsSelected)
@Html.DisplayFor(m=>m.Type)
在 checkboxfun 视图中,我有以下代码。
@model IEnumerable<MvcDropdown.Models.Mobile>
@using(Html.BeginForm())
{
@Html.EditorForModel()
<br />
<input type="submit" value="submit" />
}
现在我无法查看数据库中的数据。