[英]I created class library in .net6.0 and added my ViewComponent.I want to access my viewcomponent Default page in asp.net core mvc application
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嗨,我创建了我的类库并将我的视图组件添加到该库,我将我的 class 库的 DLL 文件添加到 asp.net mvc 应用程序我可以使用 class 和模型,但我不知道如何从库中呈现 cshtml 页面
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这就是我的调用方式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我想知道如何从 classlib 配置 cshtml 页面 我用它作为参考
https://www.davepaquette.com/archive/2016/07/16/loading-view-components-from-a-class-library-in-asp.net-core.aspx 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我的代码https://github.com/Mohammedyasith/ViewComponent
https://learn.microsoft.com/en-us/as.net/core/mvc/views/view-compilation?view=as.netcore-6.0&tabs=visual-studio#enable-runtime-compilation-conditionally https://learn.microsoft.com/en-us/as.net/core/mvc/views/view-compilation?view=as.netcore-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));
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.