Skip to content

Instantly share code, notes, and snippets.

using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc.Razor;
namespace FeatureFolderStructureDemo.StartupCustomizations
{
public class FeatureLocationExpander : IViewLocationExpander
{
public void PopulateValues(ViewLocationExpanderContext context)
{
// Don't need anything here, but required by the interface
// Include this after .AddMvc under ConfigureServices in Startup.cs
services.Configure<RazorViewEngineOptions>(options =>
{
options.ViewLocationExpanders.Add(new FeatureLocationExpander());
});
Areas seem to be like this out of the box:
/Areas
/Blog
/Controllers
BlogController.cs
/Views
Create.cshtml
...
Not like this, which is more like Feature Folders:
var dte = (DTE2) ServiceProvider.GetService(typeof (DTE));
dte.ExecuteCommand("Edit.NavigateTo", "Something.cs");
// this results in a blank NavigateTo window opening
<div is-visible="User.Identity.IsAuthenticated">
This should only be visible if you're logged in
</div>
@if (User.Identity.IsAuthenticated)
{
<div>
This should only be visible if you're logged in
</div>
}
// Add more target elements here on a new line if you want to target more than just div. Example: [HtmlTargetElement("a")] to hide/show links
[HtmlTargetElement("div")]
public class VisibilityTagHelper : TagHelper
{
// default to true otherwise all existing target elements will not be shown, because bool's default to false
public bool IsVisible { get; set; } = true;
// You only need one of these Process methods, but just showing the sync and async versions
public override void Process(TagHelperContext context, TagHelperOutput output)
{
@addTagHelper *, WebApplication1
window.Promise || document.write('<script src="https://unpkg.com/promise-polyfill@6.0.2"></script>')
window.fetch || document.write('<script src="https://unpkg.com/whatwg-fetch@2.0.2"></script>')
<script src="https://ajax.aspnetcdn.com/ajax/jquery/jquery-2.2.0.2.min.js"
asp-fallback-src="~/lib/jquery/dist/jquery.min.js"
asp-fallback-test="window.jQuery">
</script>