grouping asp.net core components folder - asp.net-core

I want to group components folder. But I can't group it because it looks for the folder name I named just below the components folder. I want to group like in the photos below:
#await Component.InvokeAsync("odemeSecenekleri")
but it is looking for "odemeSecenekleri" folder under components folder. I want " components > footer > odemeSecenekleri ". components > odemeSecenekleri not. I want to group components according to their pages.
I want to make a folders like in the photo above. Please help me.

It is really the .cshtml files which you have to be concerned about. Asp.Net Core does not care where you put the rest of the ViewComponent files.
To modify how your project searches for Views, you need to create a custom class which the implements IViewLocationExpander interface and configure it in Startup.cs
This link should help: https://stackoverflow.com/a/65983829/13550447
From what it appears you are trying to do, you may also want to consider creating Feature folders.
There are many examples if you search for Feature Folders in Asp.Net Core.
Here is one example: https://scottsauber.com/2016/04/25/feature-folder-structure-in-asp-net-core/

Related

How to extract views from Razor class libraries?

When you add Identity to your ASP.NET Core applications, you can scaffold its Razor pages.
I am looking for a way to extract my views from a referenced RCL just like Identity.
I mean I want to create Area and related files (cshtml) to help developers to customize it (not a specific UI as you see in the above pic).
Do there exist any command-line tools to a way to extract Razor pages (.cshtml)?
I checked inside of a Razor class library with dotpeek there is no HTML resource, everything is class.
Any idea?

VS 2017 ASP.NET Core Web Application and Individual User Accounts works but pages are non-existent

When I create a web project using "ASP.NET Core Web Application" / "Web Application" (non-MVC) / "Individual User Accounts"... I get the sample project with Register and Login buttons that show their respective pages when I click on them. HOWEVER... the very weird thing is if I search for "Create a new account" which is on the register page it's not found... and more... there is no AccountController in the Identity area or anywhere... so 1) the pages aren't anywhere in my solution folder and 2) how in the world are these pages showing up?!? I've tried on two different computers now. (using Core 2.1)
As an example this link works:
<a asp-area="Identity" asp-page="/Account/Login">Login</a>
and takes me to:
https://localhost:44300/Identity/Account/Login
and yet my folder structure (both in the solution and on disk) looks like this:
ASP.NET Core 2.1 with Identity automatically includes the "Default UI". It's a Razor Pages class library that's referenced via AddDefaultIdentity in Startup, which under the hood literally calls AddDefaultUI.
If you want the actual files in your project, you need to scaffold them in. Right click your project in the solution explorer and choose Add > New Scaffolded Item... Then, click the Identity listing on the left, and then the Add button. A new window will pop allowing you to select the pages you want included, your context, etc. Configure it how you like and go.
It's also worth noting, that as long as you use AddDefaultIdentity, the default UI is still included, which means you don't actually need all the scaffolded files if you want any of them. They'll essentially function as overrides. Anything specifically included in your project will be used, while anything that's missing will be pulled from the default UI.
This also means that if you want to do something like use standard controller actions and views instead of Razor Pages, the default UI will still be active, and take precedence. You have to use AddIdentity or AddIdentityCore instead of AddDefaultIdentity if you want the default UI off completely.
ASP.NET Core 2.1 introduced Razor UI in class libraries. Identity with it's UI is in nuget package.
The nice thing about this is you can now package UI with your libraries and then expose the UI for overriding.
This post describes how to override the UI. Essentially, you add the pages you want to override to your project to /Areas/Identity/Pages.... the easiest way currently is to run the scaffolder for identity and a visual walkthrough.

Keystone.JS render multiple template files

I use keystone.js together with handlebars as template engine. Until now I had one .hbs-file for each page. However, HTML-Code is growing over time and I would like to split the HTML into several files. Does keystone.js offer a simple way to render multiple template files?
I'd prefer not to use technologies like webpack just for that "simple" task.
You can use partials to break up your templates, so you can include one .hbs file in another file.
Add a new file in the templates/views/partials directory, for example myPartial.hbs, and then you can include it in another file like so:
{{> myPartial }}
KeystoneJS will handle registration of .hbs files in the templates/views/partials directory.
You can read more here:
http://handlebarsjs.com/partials.html
If you use the KeystoneJS generator to set up your project, you can see this in action where pagination.hbs is included in blog.hbs.

How to have methods in common for several (partial) views

in my asp.net core web project i have two partial views that are displaying products. the first one shows them in a big layout, while the second one displays them in a smaller, regular layout.
both partial views need a method that composes a SEO-friendly url (using the product name and further information which are provided from the ViewModel). this method should somehow be accessible to the both views.
where can i place it inside of the asp.net core application? are there any particular conventions that must be followed?
#Html.Partial("ViewName")
Uses a view in current folder with this name. If none is found, searches the Shared folder
#Html.Partial("ViewName.cshtml")
A view with this name must be in the same folder
#Html.Partial("~/Views/Folder/ViewName.cshtml")
#Html.Partial("/Views/Folder/ViewName.cshtml")
Locate the view based on the application root. Paths that start with "/" or "~/" refer to the application root
#Html.Partial("../Account/LoginPartial.cshtml")
Locate the view using relative paths

MVC4 Bundling Strategy

I'm using the new Bundling feature in ASP.NET MVC4. Currently I have the following bundles configured:
~/js/jquery
~/js/forms
˜/js/bootstrap
Depending on the view I'm serving I usually call a combination of these three (e.g. the home page on needs the jquery bundle, while the contact page needs jquery + bootstrap, while forms need all three).
My question would be: is there a way to call the three bundles to be rendered as one file from the view? I don't want to make bundles for every possible combination:
˜/js/formsAndBootstrap
˜/js/formsAndJQueryAndBootstrap
And so on...
bundles.Add(new ScriptBundle("~/bundles/formsAndBootstrap").Include(
"~/Content/Scripts/jquery-1.7.2.js",
"~/Content/Scripts/bootstrap.js",
"~/Content/Scripts/form.js"))
It appears you have to define a bundle. It can't be done "on-the-fly" from the view.