【发布时间】:2015-11-29 00:53:53
【问题描述】:
我想检查布局页面中的表格是否为空,如果它为空,我想删除导航栏中指向新闻索引的链接。
这是我目前得到的:
型号:
public class News
{
[Key]
public int NID { get; set; }
[UIHint("tinymce_jquery_full"), AllowHtml]
public string Newstext { get; set; }
[DisplayFormat(DataFormatString = "{0:yyyy/MM/dd}",
ApplyFormatInEditMode = true)]
public DateTime Datum { get; set; }
public bool Empty
{
get
{
return (NID == 0 && string.IsNullOrWhiteSpace(Newstext));
}
}
}
_Layout.cshtml:
@if (Model.Empty)
{
<li><a href="http://localhost:10075/#nyheter">Nyheter</a></li>
}
else {
}
现在的问题是它无法读取Model.Empty 是什么,如果我将@model SeikoConsulting.Models.News 放在_Layout.cshtml 的顶部,我会收到此错误:
传入字典的模型项的类型为“System.Collections.Generic.List`1[ImageSlider.Models.Gallery]”,但此字典需要“SeikoConsulting.Models.News”类型的模型项。
【问题讨论】:
标签: javascript c# html model-view-controller