Skip to main content

ASP.NET – CSS Media Queries in Razor Pages – How to embed @media syntax

If you’re working with ASP.NET MVC or ASP.NET Core using Razor pages and you want to put a CSS style within the page (CSS embed), you might stumble upon one of these following errors:

CS0103: The name ‘media’ does not exist in the current context.

CS0103: The name ‘if’ does not exist in the current context.

… And so on.

When something like that occurs, it probably means that you’re using a CSS3 media query (or other CSS3 query related commands) such as this:

Read More

Url.Action Extension Method written in C# to handle multi-language Routes in ASP.NET MVC

As anticipated here – and also by popular demand – we’re publishing an Extension Method sample that will enhance the Url.Action helper method in any Razor View allowing the developer to specify a CultureInfo object – or even a null one, to use the CultureInfo.CurrentCulture – that will be used to build a multi-language URL. Needless to say, such URL will only work if we configured a multi-language aware Route within our application such as the one we mentioned in this post.

Read More

Html.ActionLink Extension Method written in C# to handle multi-language Routes in ASP.NET MVC

As anticipated here – and also by popular demand – we’re publishing an Extension Method sample that will enhance the Html.ActionLink helper method in any Razor View allowing the developer to specify a CultureInfo object – or even a null one, to use the CultureInfo.CurrentCulture – that will be used to build a multi-language ActionLink (i.e. an ActionLink with a multi-language URL). Needless to say, such URL will only work if we configured a multi-language aware Route within our application such as the one we mentioned in this post.

Read More

ASP.NET MVC – Add custom locations to the View Engine default search patterns

One of the things I like most when developing ASP.NET application using the MVC model (if you don’t know yet what it is, read here) is the emphasis put to the project’s folder structure: the separation between the three logical aspects is reflected to the directory tree, expecially – since the Model is often injected from external libraries and their abstraction layers – the /Controllers/ and /Views/ folders, hosting respectively the input handlers and the user interface of our application.

Among these, the /Views/ folder plays a peculiar role in relation with the filesystem because it is looked by the View Engine to retrieve the View .cshtml and/or .aspx files implicitly or expicitly referenced by each Controller. The search is handled using a set of predefined patterns that come by the name of default location scheme. Here’s a portion of it, used by the Razor View Engine to lookup the standard Views:

Read More

ASP.NET – Insert HTML code in Resource Files (.resx)

We already mentioned the ASP.NET Resource Files a while ago, praising their usefulness to grant the developers an handy, centralized access to literal and media contents troughout our application projects. This is expecially convenient when developing a multilanguage website, as explained in this post). That being said, it’s not uncommon to end up having resource items containing HTML code, like shown in the following screenshot:

Read More

Close