IL.VirtualViews 1.2.1

dotnet add package IL.VirtualViews --version 1.2.1                
NuGet\Install-Package IL.VirtualViews -Version 1.2.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="IL.VirtualViews" Version="1.2.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add IL.VirtualViews --version 1.2.1                
#r "nuget: IL.VirtualViews, 1.2.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install IL.VirtualViews as a Cake Addin
#addin nuget:?package=IL.VirtualViews&version=1.2.1

// Install IL.VirtualViews as a Cake Tool
#tool nuget:?package=IL.VirtualViews&version=1.2.1                

IL.VirtualViews

Library which allows virtually register *.cshtml file as .cs classes with special attributes.

How to use

  • Reference IL.VirtualViews in your project
  • Use registration extensions coming with library to activate functionality: (IServiceCollection)services.AddVirtualViewsCapabilities() or (WebApplicationBuilder)builder.AddVirtualViewsCapabilities()
  • Use [VirtualViewPath("")] attribute for your classes with path to a view you want to register virtually
  • Derive your class from IVirtualView interface and implement the content which view is supposed to have

Examples

[VirtualViewPath("/Views/Test.cshtml")]
class Sample : IVirtualView
{
    public string ViewContent =>
    """
    @model string

    @Html.Raw(Model)
    """;
}

Virtual cshtml

There a support for .virtual.cshtml files that have build action Additional Files. Following location of such file there will be generated partial *.cs file with same name as source *.virtual.cshtml file. Autogenerated file will automatically have all the content that you have populated in .virtual.cshtml, so that you can only introduce your own(not source generated) partial part and decorate it with VirtualViewPath attribute.

Sample

/Test/Test.virtual.cshtml addded to solution with build action = Additional Files

and with content

@model string

@Html.Raw(Model)

will produce source generated file Test.g.cs:

// <auto-generated />
using IL.VirtualViews.Interfaces;

namespace VirtualViews;

public partial class Test : IVirtualView
{
    public string ViewContent()
    {
        return@"
@model string

@Html.Raw(Model)
";
    } 
}

Then you only need to create non-auto-generated partial part and decorate it with VirtualViewPath attribute with desired path original view was supposed to be handled for.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on IL.VirtualViews:

Package Downloads
IL.RulesBasedOutputCache

Rules based output cache.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.1 36 7/15/2024
1.2.0 40 7/15/2024
1.0.2 127 7/9/2024
1.0.1 68 7/9/2024