ASP.NET rendering a partial view without a model
This is one of those things that is superficially simple but has a few quirks that can take a little while to work around. I have an ASP.NET core application that has a number of different layouts. Each of these layouts needs to have a single dropdown button. The links on this button are not dynamic and so I have no need for a model.
I decided that as this was a fairly simple piece of code to use a partial view. The partial (_myButton.cshtml) just contains straight html. My first attempt at rendering used
@Html.RenderPartialAsync("_myButton")
Unfortunately for reasons I have been unable to determine, this rendered spurious text adjacent to the button
As a result, I decided to abandon my attempt to be async and used
@Html.RenderPartial("_myButton")
This now refused to build, generating error CS0029 as it wanted a model. Trying to pass null as a model only returned further errors.
The thing that finally worked for me was to use the following
@{Html.RenderPartial("_myButton");}
and now I can happily re use the button at will