我在 web.config 中声明我的价值观
<appSettings>
<add key="SystemName" value="RealState Premium" />
<add key="SystemDescription" value="Sistema de Administração Imobiliário" />
</appSettings>
配置模型:
public class _Header
{
public string SystemName { get; set; }
public string SystemDescription { get; set; }
}
控制器:
[AllowAnonymous]
public ActionResult _Header()
{
HomeModels._Header headerModel = new HomeModels._Header();
headerModel.SystemName = ConfigurationManager.AppSettings["SystemName"];
headerModel.SystemDescription = ConfigurationManager.AppSettings["SystemDescription"];
return PartialView(headerModel);
}
最后,查看:
@using realstate.Models
@model HomeModels._Header
<div class="logo">
<img src="~/Images/logo/logo.png" alt="Mercado de Imóveis" />
<table class="sysTitleTbl">
<tr>
<td class="name">@Model.SystemName</td>
</tr>
<tr>
<td class="description">@Model.SystemDescription</td>
</tr>
</table>
</div>
问题是我在@Model.SystemName 中得到了一个空引用,这会是什么问题?