(TagHelper学习相关连接:https://www.cnblogs.com/shenba/p/6697024.html)

这里使用TagHelperOutput提供的SuppressOutput方法。
新建如下TagHelper
[HtmlTargetElement(Attributes = "show-for-action")]
public class SelectiveTagHelper : TagHelper
{
public string ShowForAction { get; set; }
[ViewContext]
[HtmlAttributeNotBound]
public ViewContext ViewContext { get; set; }
public override void Process(TagHelperContext context,
TagHelperOutput output)
{
if (!ViewContext.RouteData.Values["action"].ToString()
.Equals(ShowForAction, StringComparison.OrdinalIgnoreCase))
{
output.SuppressOutput();
}
}
}
这个TagHelper定义了其标签内容只有在当前Action跟目标Action一致的时候在显示内容,否则调用Suppress禁止内容输出
比如如下html标记
<div show-for-action="Index" class="panel-body bg-danger">
<h2>Important Message</h2>
</div>
指定了只有在Index action下才显示important Message



如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using TemplateTest1.Models;
namespace TemplateTest1
{
public class EFContext : DbContext
{
public EFContext()
: base("Default")
{
}
public DbSet<AdGroupAdPositions> AdGroupAdPositions { get; set; }
public DbSet<CompanyAddresses> CompanyAddresses { get; set; }
public DbSet<AdPositions> AdPositions { get; set; }
public DbSet<CompanyContacts> CompanyContacts { get; set; }
//还有很多属性
}
}
在以前的 ASP.NET 版本中,我们将应用程序配置设置(例如数据库连接字符串)存储在web.config文件中。 在 Asp.Net Core 中, 应用程序配置设置可以来自以下不同的配置源。
相关连接:https://www.seoxiehui.cn/article-148803-1.html


区域提供了一种将大型web应用程序划分为易于管理的较小功能单元的方法

假设说最后一项,每个开发要使用自己本机的数据库,你可能会说让每个人修改自己的web.config,在提交代码的时候不提交就行了。那么如果在web.config添加其他配置项的时候,显然不提交web.config文件不合理的。
现在,ASP.NET Core 提供了一种很优雅简洁的方式 User Secrets 用来帮助我们解决这个事情
(相关连接:https://www.cnblogs.com/savorboard/p/dotnetcore-user-secrets.html)

原文:https://www.cnblogs.com/gougou1981/p/12199658.html