Hi I created my classlib and added my viewcomponents to that library and I added DLL file of my class library to asp.net mvc application I can able to use class and models but I don't know how to render cshtml page from library

this is my library enter image description here

this is how I configred it now enter image description here

this is how I call enter image description here

Add the problem is enter image description here

I want to know how to configure cshtml page from classlib I use this as reference

https://www.davepaquette.com/archive/2016/07/16/loading-view-components-from-a-class-library-in-asp-net-core.aspx

My Code https://github.com/Mohammedyasith/ViewComponent

1

There are 1 best solutions below

0
Yasith 63 On

https://learn.microsoft.com/en-us/aspnet/core/mvc/views/view-compilation?view=aspnetcore-6.0&tabs=visual-studio#enable-runtime-compilation-conditionally

Follow This Link to configer

using Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation;
using Intelizign.Net.ViewComponents.NavBarViewComponent;
using Microsoft.Extensions.FileProviders;


var builder = WebApplication.CreateBuilder(args);

var env = builder.Environment;

builder.Services.AddRazorPages().AddRazorRuntimeCompilation();

var mvcBuilder = builder.Services.AddRazorPages();

if (builder.Environment.IsDevelopment())
{
    mvcBuilder.AddRazorRuntimeCompilation();
}

builder.Services.AddControllersWithViews();

builder.Services.AddApplicationInsightsTelemetry();

builder.Services.Configure<MvcRazorRuntimeCompilationOptions>(o =>
{   
    var libraryPath = Path.GetFullPath(
        Path.Combine(builder.Environment.ContentRootPath, "..", "vLib"));
    o.FileProviders.Add(new PhysicalFileProvider(libraryPath));             

});