Pass empty model to razor view

i needed to pass empty instance for a model i have to my razor view so Vue (as my client side) can use it, as i was avoiding re-type the whole model again.

usually when you pass you model with values in ViewBag if you use
@Html.Raw(ViewBag.ModelClass)

you get Json, but to my surprise that is not the case if it's just an empty no values instance, in that case this code will return the object name!

to solve this i added Json.Serialize to the mix, so
@Html.Raw(Json.Serialize(ViewBag.ModelClass))

will return an empty value json representing the model empty instance.

Popular posts from this blog

how to copy NuGet packages from one project to another

How to load a DLL and runtime, invoke a method by name, get result object and use it as a parameter on another unkown DLL .NET Core

Blazor how to generate that SHA256 check