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 - asp.net-core-mvc

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

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));
});

Related

Add button for new page created by Link in Vaadin application

I have Vaadin app that provides some calculations.
As a result of these calculations, the application redirects me to the file system through Link-mechanism, so that I have new page with many new Links.
So the question is how to add to this page one button?
Initial link looks like:
public static Link linkToNewTab(String caption, String url) {
Link lnk = link(caption, url);
lnk.setTargetName("_blank");
return lnk;
}

How to change header section based on url query param in reactjs

I have developed web app using ReactJS when i navigate one page to another page the header text should be changed based url (i created header component and i did import in all pages) how to achieve this
if you are using client-side use javascript to handle it:
componentDidUpdate(){
var path= window.location.pathname; // lets imaging that url is "/home/x"
var pathArray = path.split( '/' );
var loc= pathArray[2];//number of part of url that is changing, here it rerurns x
if(loc === "product"){ // if x be "product" it returns true
//do somting
}
}
if using server-side rendering instead of using "var path= window.location.pathname;" it's better to save URL path in store and use it in your component.

How to dynamically add view in page or layout

I can't figure out how to programatically add a view into a layout or page.
I need to add views at runtime without using static xml declaration since i need to fetch them from an http requested object... . I didn't find useful informations in the docs.
Anyone knows how to do?
I think you meant to dynamically add some view / controls to the page rather than to navigate into another page.
If so, you just need to add some controls into one of the layouts in your page (only containers [=layouts] can have multiple children.
so, your code (viewmodel/page controller) would look something like:
var layout = page.getViewById("Mycontainer");
// create dynamic content
var label = new Label();
label.text = "dynamic";
// connect to live view
layout.addChild(label)
In addition to having a page included inside your app (normal); you download the xml, css, & js to another directory and then navigate to it by then doing something like page.navigate('downloaded/page-name');
you can also do
var factoryFunc = function () {
var label = new labelModule.Label();
label.text = "Hello, world!";
var page = new pagesModule.Page();
page.content = label;
return page;
};
topmost.navigate(factoryFunc);
https://docs.nativescript.org/navigation#navigate-with-factory-function
You should check out this thread on the {N} forum.
The question is about dynamically loading a page and module from a remote server. The (possible) solution is given in this thread.

checkbox for dropdownlist

I am binding drodownlist from Db as shown below:
ddlTemplates.DataSource = ObjBlTemplate.DsGetTemplate;
ddlTemplates.DataTextField = "templateTitle";
ddlTemplates.DataValueField = "templateID";
ddlTemplates.DataBind();
I need to display checkbox for each and every field.
In asp.net you have not any built in function to do this.If you want to use javascript with your asp.net code link here is a example about this.

Loading an image from resources in an unreferenced assembly

I have two silverlight assemblies, CaseManager.Applet and CaseManager.Applet.Sample. The Sample assembly has a reference to the base Applet assembly. The sample assembly has an embedded resource png image. The base applet assembly has a view xaml that I wish to display that image programmatically.
In the sample assembly I have a bit of code that creates a Uri like so:
var icon = new AppletIcon()
{
ImageUri = new Uri("CaseManager.Applet.Sample;component/images/guiness_2.png", UriKind.Relative),
ModuleType = GetType(),
Text = "Sample Module"
};
When I execute this code all the properties of ImageUri throw InvalidOperationException. I am not sure why. Anyone have suggestions?
The following code does the job:
var icon = new AppletIcon()
{
ImageUri = new Uri("/CaseManager.Applet.Sample;component/images/guiness_2.png", UriKind.Relative),
Module = this,
Text = "Sample Icon"
};
Things to note here:
The slash at the start of the Uri string.
The short name of the assembly containing the resource.
the ;component/ section.
From there it is basically the path inside your project to the image. Hope this helps someone else.
For what it was worth I was missing the very first slash.

Resources