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

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

ASP.NET MVC 4 – for loop posts model collection properties but foreach does not

the problem is not with the IEnumerable or the IList it the way you are rendering the collection in your view. @for(var i = 0;i < Model.People.Count;i++) { <tr> <td>@Html.TextBoxFor(m => Model.People[i].Name)</td> <td>@Html.TextBoxFor(m => Model.People[i].Age)</td> </tr> } Observe that with each list item you are appending a continuous index which enables the model binder to … Read more