I'm trying to apply localization on _Layout.cshtml
_Layout.cshtml
#using Microsoft.AspNetCore.Http.Extensions
#using Microsoft.AspNetCore.Localization
#using Microsoft.AspNetCore.Mvc.Localization
#inject Microsoft.ApplicationInsights.AspNetCore.JavaScriptSnippet JavaScriptSnippet
#inject IViewLocalizer LayoutLocalizer
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<div style="margin:38px;margin-top:56px;" class="hidden-sm-down">
<h2>#LayoutLocalizer["WelcomeHeader"] <b class="text_border_darkblue">MyTitle</b></h2>
<div style="text-align:center;margin-top:42px;">
#LayoutLocalizer["WelcomeSub"]
</div>
</div>
</body>
</html>
The resource files are named named: Views.Shared._Layout.no.resx (I've tried renaming to views.shared.Layout.no.resx without any luck)
You must create a _Layout.no.resx file within the same path of the views but as a root the "Resources" folder. See sample image:
There is a video clarifying the use of Location see here
Solution
Implement SharedResources with resource files and use Localization on
the SharedResources object in shared Views
You can combine IViewLocalizer and IHtmlLocalizer for _Layout.cshtml. If you define a resource folder inside your Visual Studio solution you can put the resource files there.
If you are using razor pages instead of MVC views inside your ASP.net core application you create a subfolder Pages instead of Views inside the folder Resources. Put the _Layout.no.resx file in there. e.g. Resources\Pages\_Layout.no.resx.
Related
Where point razor folders "_framework" and "_content"?
_host.cshtml
<script src="_framework/blazor.server.js"></script>
<script src="_content/BlazorInputFile/inputfile.js"></script>
there is no inputfile.js nor a BlazorInputFile folder
simple answer for _content: to wwwroot of those library.
what about _framework? Root directory of library?
I'm building the ASP.Net Core Web Application
I installed bootstrap using Quick Install Package. So now I have it in my dependencies:
Also, there's a folder "node_modules" with bootstrap and everything is fine there, all classes are where they're supposed to be:
Then I created a view and in html wrote the following:
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.css" />
When I hover the mouse over the href, I see a warning:
Path C:\Users\Shep\SportsStore\SportsStore\wwwroot\~node_modules not found
Well, it's true, because there's no such folder, but how to keep it from looking in wwwroot and use the specified folder? My wwwroot is empty, I guess it's because I didn't use bower
If I use the full path (href="C:/Users/Shep/SportsStore/SportsStore/node_modules/bootstrap/dist/css/bootstrap.css"), it seems right, but I bootstrap classes are unavailable:
<body>
<div class="panel-info">
</div>
</body>
and if I hover the mouse over, I see "Unknown CSS class 'panel-info'" even though there's this class in bootstrap.css
.panel-info {
border-color: #bce8f1;
}
I'm not using Angular and haven't created any js files of my own yet.
I have seen lots of similar issues and haven't found suitable solution, sorry if it's a duplicate
In ASP.NET Core, the runtime supports a piece of middleware called StaticFiles that allows anything in the /wwwroot folder to be accessible from the browser. But since the node_modules directory is outside of /wwwroot ,that problem occurs .
You can use Library Manager/Bundler and Minifier to copy the files into wwwroot . There are a lot of solutions you could find from here .
I have a .NET Core project in which the master page _Layout.cshtml page references site wide style and js files:
<link rel="stylesheet" href="~/css/site.css" />
<script src="~/js/site.js" asp-append-version="true"></script>
The Index.cshtml page, which utilizes the above master page, references page specific style and js files:
<link type="text/css" rel="stylesheet" href="~/css/landing.css">
<script src="~/js/landing.js" asp-append-version="true"></script>
And then Contact.cshtml and About.cshtml also have page specific css and js files.
What is the correct method to bundle the site wide files with page specific files?
Should I avoid referencing anything the in the master page and simply reference the bundled file in each page's .cshtml?
You reference in your Master Page all scripts and Style Sheets you share across pages. For instance, you could reference only jquery.
You reference in your pages scripts and styles that are used specific on that pages.
It sounds simple like that.
I write #inject IHtmlLocalizer Localizer in _Layout.cshtml, but it isResourceNotFound = true? why?
The structure of the Resources folder might not follow the structure of the Views folder. By convention, _Layout.cshtml is located in the Views/Shared folder. Therefore, your Resources folder should reflect that: resource files for the layout should be in Resources/Views/Shared folder.
I have a specific _ViewStart.cshtml and _Layout.cshtml (in a sub folder of the Views folder) for a webpage and when the page is loaded the _ViewStart and _Layout are used as expected (breakpoint is reached in _ViewStart)
I have a _ViewStart.cshtml and _Layout.cshtml in the Shared folder (of Views folder) that I want all my other views to reference.
The _Layout is being reference but the _ViewStart.cshtml is not (breakpoint not reached) - is this the norm in mvc3?
Also, my first view that uses the shared layout shows the DOCTYPE directive at the top of the webpage (using firebug), however the subsequent webpage is missing the DOCTYPE directive, even though it uses the same _Layout.cshtml - any ideas why?
Found I had a "Response.Write..." in my view which caused the DOCTYPE declaration not to be printed.