Month: July 2019

A @section Scripts block does not work when placed in a partial view in ASP.NET Core, which is the same functionality as in ASP.NET MVC. Unfortunately, you don't get any error messages if you try to add the section to a partial -- it just does nothing. In many cases, having a scripts section in a partial view would be an anti-pattern, since the partial can be rendered an unknown number of times. However, there are times when I believe a scripts section is warranted in a partial, particularly when you're trying to create dynamic JavaScript based on the model passed into the partial view. While you can't just use the actual @section Scripts in a partial view, you can add some HTML helper extensions to accomplish the same thing.

Continue reading »