asp.net conditionally disable a tag helper (textarea)

It is actually very simple, the disable attribute is already working as you want – you can pass in a boolean value: <textarea asp-for=”Doc” disabled=”@Model.MustDisable”></textarea> if false the disabled attribute is not rendered: <textarea></textarea> if true the disabled attribute is set to “disabled”: <textarea disabled=”disabled”></textarea>

.Net Core on Raspberry Pi 4 with Raspbian?

Download .Net Core 3.1 SDK from HERE Make Directory: sudo mkdir /usr/share/dotnet/ PATH to environment: export PATH=$PATH:/usr/share/dotnet/dotnet export DOTNET_ROOT=/usr/share/dotnet/dotnet or just a symlink sudo ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet Copy by Extracting: sudo tar zxf dotnet-sdk-3.1.100-linux-arm.tar.gz -C /usr/share/dotnet/ Confirm Installation: dotnet –info you can find in detail from Here

How do you unit test ASP.NET Core MVC Controllers that return anonymous objects?

Original idea from this answer with a more generic approach. Using a custom DynamicObject as a wrapper for inspecting the value via reflection there was no need to add the InternalsVisibleTo public class DynamicObjectResultValue : DynamicObject, IEquatable<DynamicObjectResultValue> { private readonly object value; public DynamicObjectResultValue(object value) { this.value = value; } #region Operators public static bool … Read more

ASP.Net Core MVC – Client-side validation for custom attribute

The IClientModelValidator is in fact the right interface. I’ve made a contrived sample implementation below. Attribute [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = false)] public sealed class CannotBeRedAttribute : ValidationAttribute, IClientModelValidator { public override bool IsValid(object value) { var message = value as string; return message?.ToUpper() == “RED”; } public void AddValidation(ClientModelValidationContext context) { MergeAttribute(context.Attributes, “data-val”, … Read more

ToArrayAsync() throws “The source IQueryable doesn’t implement IAsyncEnumerable”

I found I had to do a bit more work to get things to work nicely: namespace TestDoubles { using Microsoft.EntityFrameworkCore.Query.Internal; using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Threading; using System.Threading.Tasks; public static class AsyncQueryable { /// <summary> /// Returns the input typed as IQueryable that can be queried asynchronously /// </summary> /// … Read more

How to add IHttpContextAccessor in the Startup class in the DI in ASP.NET Core 1.0?

It is no longer a default service. You have to configure it in Startup.cs services.TryAddSingleton<IHttpContextAccessor, HttpContextAccessor>(); services.TryAddSingleton<IActionContextAccessor, ActionContextAccessor>(); UPDATE: In ASP.NET Core 2.1, the AddHttpContextAccessor helper extension method was added to correctly register the IHttpContextAccessor with the correct lifetime (singleton). So, in ASP.NET Core 2.1 and above, the code should be services.AddHttpContextAccessor(); services.TryAddSingleton<IActionContextAccessor, ActionContextAccessor>(); Source: … Read more

How to specify the view location in asp.net core mvc when using custom locations?

Great news… In ASP.NET Core 2 and up, you don’t need a custom ViewEngine or even ExpandViewLocations anymore. Using the OdeToCode.AddFeatureFolders Package This is the easiest way… K. Scott Allen has a nuget package for you at OdeToCode.AddFeatureFolders that is clean and includes optional support for areas. Github: https://github.com/OdeToCode/AddFeatureFolders Install the package, and it’s as … Read more