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>

When to use @await Html.PartialAsync in a View in MVC 6

This is actually a pretty interesting question and scenario. To a certain extent, async is the new hotness (though it’s really not all that new). Entity Framework 6 hit with async methods and every… single… piece… of… documentation… suddenly starting using async for everything. I think we’re seeing a little of the same here. MVC … Read more

Replacement for @helper in ASP.NET Core

According to the following Github issue, it looks like @helper is coming back and will be included in asp .net core 3.0.0 preview 4. https://github.com/aspnet/AspNetCore/issues/5110 UPDATE Starting in asp .net core 3, you can now define a local function within a Razor code block. @{ void RenderName(string name) { <p>Name: <strong>@name</strong></p> } RenderName(“Mahatma Gandhi”); RenderName(“Martin … Read more

razor syntax – foreach loop

Just saw this on ScottGu’s blog this morning: use @: before that line: @foreach (string s in “1,2,3”.Split(‘,’)) { @: s is equal to @s<br/> } Alternately, use the <text /> tag: @foreach (string s in “1,2,3”.Split(‘,’)) { <text>s is equal to @s<br/></text> }

IntelliSense in Razor files (.cshtml) stopped working

This is what worked for me after IntelliSense suddenly began to bug out and stopped colouring C# code correctly in between the HTML tags in my views: Just delete the contents of the folder at %LOCALAPPDATA%\Microsoft\VisualStudio\16.0_<hash>\ComponentModelCache As an additional step, you can optionally run the command DevEnv.exe /setup in Developer Command Prompt for VS (as … Read more

Pass parameter to controller from @Html.ActionLink MVC 4

You are using a wrong overload of the Html.ActionLink helper. What you think is routeValues is actually htmlAttributes! Just look at the generated HTML, you will see that this anchor’s href property doesn’t look as you expect it to look. Here’s what you are using: @Html.ActionLink( “Reply”, // linkText “BlogReplyCommentAdd”, // actionName “Blog”, // routeValues … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)