This is a question about something fundamental but I've searched far and I can't find a convincing answer. I want to JSON encode a whole model which includes a list of objects. The advice in every topic is to do @Html.Raw(Json.Encode(@Model)). But I'm trying that and the list is being encoded as [Object, Object, Object]. Useless because I want the actual information inside these objects.

I know you can create a JSON manually and include each separate part of your Razor model. But this just seems daft because what is the point in the encoding shortcut in the first place if I have to explicitly create JSON objects for any vaguely or remotely complex model?

Surely there must be some common tool or technique that simply takes a Razor model and turns it into a JSON which includes the complete information of the model.

Related posts

Recent Viewed