我正在 MVC3 asp.net 上开发一个网站,我使用实体框架作为数据库:我想在 _Layout.cshtml 上显示数据库中的徽标,并且我想将数据库中的文本显示到我的主页中。这是我的模型
public class Theme
{
[Required(ErrorMessage = "ID is required.")]
public string ThemeID { get; set; }
public string path { get; set; }
[AllowHtml]
[Required(ErrorMessage = "Text is required.")]
public string texte { get; set; }
}
我把 _Layout.cshtml
@Html.Partial("~/Views/Shared/_Header.cshtml")
这是我的 ThemeController.cs
[ChildActionOnly]
public ActionResult Header(string id)
{
var model = db.Themes.ToList();
return View("~/Views/Shared/_Header.cshtml", model);
}
这是 _Header.cshtml
@model ICollection<DSClient.Models.Theme>
@{
<img src="@Href( @Model.ElementAt(@Model-1).path )" />
}
当我输入 Theme/index 的 url 时没关系,但问题是当我加载其他页面时,我有这个异常对象引用未设置为对象的实例。拜托我需要你的帮忙。