在一年中的某些时候,在我的 mvc 应用程序中,我们希望显示两个链接之一。基本上,当我接到管理层的电话时,我必须切换链接。因此,我认为不必重新编译应用程序,而是将自定义应用程序设置添加到 web.config 文件。然后我创建了一个包装器,以便它是强类型的。现在,我的问题是我不知道在哪里执行逻辑。应该向我的视图模型添加一个属性并根据配置设置值在控制器中设置它吗?或者我应该直接在我的视图中阅读它并在两个链接之间切换?我很确定这仅属于视图或控制器,而不属于服务层,因为它专门用于 UI 内容。
Details.cshtml //当前代码
@if(Search.App.ParcelDetailDisplayMode == Search.App.DisplayMode.Tax ){
<a id="tax-link" href="@taxlink" title="View Tax Bill on Tax Collectors Website">Tax Bill</a>
}
else if(Search.App.ParcelDetailDisplayMode == Search.App.DisplayMode.Trim ){
<a id="trim-link" href="@trimlink" title="View your TRIM notice online">Trim Notice</a>
}
网络配置
<add key="ParcelDetailDisplayMode" value="Tax"/>
配置包装器
namespace Search
{
/// <summary>
/// The app.
/// </summary>
public static class App
{
/// <summary>
/// Gets the tax bill link.
/// </summary>
public static string TaxBillLink
{
get
{
return ConfigurationManager.AppSettings["TaxBillLink"];
}
}
/// <summary>
/// Gets the trim notice link.
/// </summary>
public static string TrimNoticeLink
{
get
{
return ConfigurationManager.AppSettings["TrimLink"];
}
}
/// <summary>
/// Gets the map link.
/// </summary>
public static string MapLink
{
get
{
return ConfigurationManager.AppSettings["MapLink"];
}
}
/// <summary>
/// Gets the update address link.
/// </summary>
public static string UpdateAddressLink
{
get
{
return ConfigurationManager.AppSettings["UpdateAddressLink"];
}
}
/// <summary>
/// Gets the release name.
/// </summary>
public static string ReleaseName
{
get
{
return ConfigurationManager.AppSettings["ReleaseName"];
}
}
/// <summary>
/// Gets the parcel detail display mode.
/// </summary>
public static DisplayMode ParcelDetailDisplayMode
{
get
{
var r = DisplayMode.Tax;
DisplayMode.TryParse(ConfigurationManager.AppSettings["ParcelDetailDisplayMode"], out r);
return r;
}
}
/// <summary>
/// The display mode.
/// </summary>
public enum DisplayMode
{
/// <summary>
/// The trim.
/// </summary>
Trim,
/// <summary>
/// The tax.
/// </summary>
Tax
}
}
}