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

Formatting Razor Files in Visual Studio Code

You can introduce them as HTML files (File -> Preferences -> Settings) without any 3rd party extensions: { “editor.formatOnSave”: true, “emmet.includeLanguages”: { “aspnetcorerazor”: “html” }, “files.associations”: { “*.cshtml”: “html” } } Update: v1.17.0 of C# for Visual Studio Code add-on added preview Razor (cshtml) language service with support for C# completions and diagnostics.

VS 2015 Razor Autocomplete/Intellisense dropdown hides immediately after dropdown

I haven’t found the root cause, but in all cases, CTRL+SPACE works. This isn’t the best, but light years better than nothing at all. (this shortcut is not one I’ve used in the past, so this is likely standard behavior, but…) If you’re at the dot Model. and autocomplete list disappears, CTRL+SPACE consistently brings it … Read more

How to use Bootstrap modal in Blazor client app?

There is likely a better way to do this, but here’s a working example to get you started: Page: @page “/modal-test” <BlazorApp1.Components.Modal @ref=”Modal”></BlazorApp1.Components.Modal> <button @onclick=”() => Modal.Open()”>Open Modal</button> @code { private BlazorApp1.Components.Modal Modal { get; set; } } Component: <div class=”modal @ModalClass” tabindex=”-1″ role=”dialog” style=”display:@ModalDisplay”> <div class=”modal-dialog” role=”document”> <div class=”modal-content”> <div class=”modal-header”> <h5 class=”modal-title”>Modal title</h5> … Read more

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