我有什麼應該是從SQL中的表格到HTML.EditorFor幫助器的簡單數據集。 我的問題是在數據庫中的記錄是布爾值,我需要依靠,如果值是1或0MVC 5 EF 6 EditorFor下拉列表更改顯示文本
我的編輯模板看起來像這樣顯示的文本字符串:
@model nData.DAL.tblTaggingGroupInstance
<td>
@Html.DisplayFor(modelItem => modelItem.WeekDay)
</td>
<td>
@Html.DisplayFor(modelItem => modelItem.Segment)
</td>
<td>
@Html.DisplayFor(modelItem => modelItem.NetSales)
</td>
<td>
@Html.DisplayFor(modelItem => modelItem.SwellSales)
</td>
<td>
@Html.DisplayFor(modelItem => modelItem.SpikeSales)
</td>
<td>
@Html.EditorFor(modelItem => modelItem.Recurring)
</td>
<td>
@Html.EditorFor(modelItem => modelItem.tblTaggingReasonID)
</td>
<td>
@Html.EditorFor(modelItem => modelItem.Comment)
</td>
我的型號是:
public partial class tblTaggingGroupInstance
{
public int ID { get; set; }
public int tblTaggingGroupID { get; set; }
public int FinYear { get; set; }
public int FinWeek { get; set; }
public int WeekDay { get; set; }
public Nullable<int> tblTaggingReasonID { get; set; }
public Nullable<decimal> NetSales { get; set; }
public Nullable<decimal> SwellSales { get; set; }
public Nullable<decimal> SpikeSales { get; set; }
public string Comment { get; set; }
public string Segment { get; set; }
public Nullable<bool> Recurring { get; set; }
public Nullable<decimal> BaseSales { get; set; }
public virtual tblTaggingGroup tblTaggingGroup { get; set; }
}
和控制器是
public ActionResult Index()
{
var SelectedID = Convert.ToInt32(Session["_SessionSelectGroupID"]);
var SelectedYear = Convert.ToInt32(Session["_SessionSelectFinYear"]);
var SelectedWeek = Convert.ToInt32(Session["_SessionSelectFinWeek"]);
var tblTaggingGroupInstances = db.tblTaggingGroupInstances.Include(t => t.tblTaggingGroup);
return View(tblTaggingGroupInstances.Where(t => t.tblTaggingGroupID == SelectedID && t.FinYear == SelectedYear && t.FinWeek == SelectedWeek).ToList());
}
[HttpPost]
public ActionResult Index(List<tblTaggingGroupInstance> model)
{
foreach (var record in model)
{
db.Entry(record).State = EntityState.Modified;
}
db.SaveChanges();
return RedirectToAction("Index");
}
什麼是最簡單/最簡單的方式來更改顯示的文本,而不影響回發到數據庫的值?
感謝 馬克
您是否指'可空值重複性'屬性?你想顯示什麼文字? –
是的,這是我需要說的定期或非定期取決於值是1還是0. – Readamus
它可以爲空,所以當它的'null'時你想要顯示什麼?一種選擇是使用一個包含文本的附加'string'屬性的視圖模型,幷包含一個隱藏的屬性輸入(但是如果你想編輯它並更新顯示文本,那麼你將需要javascript) –