Changing default folder location in MVC project folder structure - asp.net-mvc

Is there any way to set default Contents location in different path or using different name instead of Contents?
Edit:
Thus, I can download bootstrap or something else from nuget which are related with Content folder into the new directory.

You can use whatever name you like. Just rename the folder and update your BundleConfig to reflect the new name:
bundles.Add(new StyleBundle("~/SomeOtherName/css").Include(
"~/SomeOtherName/bootstrap.css",
"~/SomeOtherName/site.css"));
And in the _Layout.cshtml make sure to include the correct name:
#Styles.Render("~/SomeOtherName/css")

Related

How can I reference a script that is in my pages directory?

I'm trying to keep a good practice of keeping context together and in that regard, I like how Razor Pages forces you to place your view models next to its view. I'd like to do this with script files as well.
For example, if script is a bit large and is only used on this particular page, it may not be the cleanest thing to have it in a render section in the cshtml. Instead, I'd want to place it into its own .js file. But to keep the project easy to navigate for team members, I'd like to place that .js file in the same folder next to its view and view model. I'm not sure how to link that file, or if I even can. If I give src a path to the file, it is not found. Assuming that's because wwwroot is the only folder setup to host static files.
Suggestions?
You can add an option to the StaticFilesProvider in your Configure method:
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(),"Pages")), RequestPath="/Pages"
});
See the documentation on Static Files in ASP.NET Core: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-2.1

How to acess AreasController that is in controller folder that is outside of .Net's Areas Folder

I have a Controller called AreasController, I added Areas folder to the project so I can create some Areas, by doing this I noticed that the url: /Areas is pointing to Areas folder not to my AreasController.
Is there a way to solve this, or I'll have to rename AreasController.
You can specify the associated route to that controller by adding an annotation on the top of the class name
as here:
[Route("Areas")]
for more reading please check Microsoft docs

grails elfinder plugin: use placeholder in rootDir

in my Grails project I'm using elfinder plugin to manage files and directories. I want to have a dynamic root directory, because I use the plugin for different folders.
The path of directory is like the following:
grails.plugin.elfinder.rootDir = "${userHome}/docm_patients_doc/{patientcf}/"
where patientcf is the id of an entity in my application. When I enter into the show.gsp page of that entity, I need to replace the patientcf with the related value.
How can I do it?
EDIT:
I've tried to modify the placeholder before the script and div that shows elfinder in gsp page, but I notice that the path is not modified. Maybe the gsp is not the place in which the placeholder can be modified...
I am author of elfinder plugin, though plugins isn't developed with multiple roots in mind.
You can try this. Plugin registers a spring bean with name elfinderFileManager which has a property with name ‘root’ which is path to your root directory. Try setting the root property at runtime. The bean can be injected in your controller/service and you can try changing the root property.

ASP.NET MVC 4 bundle with wildcard in folder path

My team uses a custom NuGet package for installing jQuery UI, which puts the theme files into a directory structure like this:
Content
jquery-ui-1.10.3
images
jquery-ui.css
jquery-ui.min.css
I'm trying to use ASP.NET MVC 4 bundles to include this content in the BundleConfig class inside my application's App_Start folder like so:
bundles.Add( new StyleBundle( "~/bundles/css" )
.Include( "~/Content/normalize-{version}.css",
"~/Content/jquery-ui-{version}/jquery-ui.css",
"~/Content/Site.css" ) );
This throws an error when I run the site:
Directory does not exist.
Parameter name: directoryVirtualPath
I also tried:
bundles.Add( new StyleBundle( "~/bundles/css" )
.Include( "~/Content/normalize-{version}.css" )
.IncludeDirectory( "~/Content/jquery-ui-*", "*.css" )
.Include( "~/Content/Site.css" ) );
That doesn't work either (obviously). I can explicitly specify the version on the folder, but that defeats part of the benefit of using the bundle.
So how can I use a wildcard in the folder path?
You could use the overloaded version of IncludeDirectory which searches subdirectories.
Suppose you have the following file:
\Root\Content\jquery-ui-1.10.3\jquery-ui.css
Use this code to find and add it:
.IncludeDirectory("~/Content", "jquery-ui.css", true)
This is useful because it will always find jquery-ui.css, regardless of where you put it.
The downside to this method is that it will search for and include all jquery-ui.css files that it finds, which could cause some bugs if you don't ensure that only one jquery-ui.css exists.
(Remember that searching for subdirectories will also still search the root directory i.e. ~/Content)

How to determine location of wrapper (relative to module - and not theme folder) in placement info file?

i am trying to specify a cshtml file as wrapper for specific ContentType in a placementinfo file.
my definition looks like this :
<Place Parts_Estate="Content:4;Wrapper=OrderResultItemWrapper"/>
now the problem is that , when i investigate the contentItem in ShapeTracing window i figured out that the search location for Wrapper view file is theme folder.
~/Themes/EmlakTheme/Views/OrderResultItemWrapper.cshtml
anyone have any idea how to convince the view engine to search within module folder rather than theme folder.
any help is very appreciated.
EDIT:
my problem is as follow :
1 - i have placed a cshtml file as a wrapper in the module's directory.
2 - i haven't placed any copy of (and not any other file with this name) in the theme folder
3 - the wrapper doesn't affect my shape.
4 - when i searched for problem i found out that shape tracing window showing the
"~/Themes/EmlakTheme/Views/OrderResultItemWrapper.cshtml"
path.that means it doesn't search the modules directory for my wrapper file and results in not displaying the wrapper.
EDIT
My problem have been solved.
my mistake was adding wrapper to DisplayTemplate directory.i have placed it in Views (root) directory and now it is working well.thanks all guys participating in answer.
If you have the same cshtml file in both a module and a theme, the latter will take precedence. If you need to use the one provided by module - delete the one from the theme.

Resources